# -*- coding: utf-8 -*- """ Command line test ~~~~~~~~~~~~~~~~~ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for 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 import support TESTFILE, TESTDIR = support.location(__file__) 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 = TESTFILE c, o, e = run_cmdline("-Ofull=1,linenos=true,foo=bar", "-fhtml", filename) self.assertEquals(c, 0) self.assert_("foo, bar=baz=," in o) def test_F_opt(self): filename = TESTFILE c, o, e = run_cmdline("-Fhighlight:tokentype=Name.Blubb," "names=TESTFILE filename", "-fhtml", filename) self.assertEquals(c, 0) self.assert_('