# -*- coding: utf-8 -*- """ Command line test ~~~~~~~~~~~~~~~~~ :copyright: 2006-2007 by Georg Brandl. :license: BSD, see LICENSE for more details. """ # Test the command line interface import sys, os import unittest import StringIO from pygments import highlight from pygments.cmdline import main as cmdline_main def run_cmdline(*args): saved_stdout = sys.stdout saved_stderr = sys.stderr new_stdout = sys.stdout = StringIO.StringIO() new_stderr = sys.stderr = StringIO.StringIO() try: ret = cmdline_main(["pygmentize"] + list(args)) finally: sys.stdout = saved_stdout sys.stderr = saved_stderr return (ret, new_stdout.getvalue(), new_stderr.getvalue()) class CmdLineTest(unittest.TestCase): def test_L_opt(self): c, o, e = run_cmdline("-L") self.assertEquals(c, 0) self.assert_("Lexers" in o and "Formatters" in o and "Filters" in o and "Styles" in o) c, o, e = run_cmdline("-L", "lexer") self.assertEquals(c, 0) self.assert_("Lexers" in o and "Formatters" not in o) c, o, e = run_cmdline("-L", "lexers") self.assertEquals(c, 0) def test_O_opt(self): filename = os.path.join(testdir, testfile) c, o, e = run_cmdline("-Ofull=1,linenos=true,foo=bar", "-fhtml", filename) self.assertEquals(c, 0) self.assert_("