diff options
Diffstat (limited to 'tests/test_terminal_formatter.py')
-rw-r--r-- | tests/test_terminal_formatter.py | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/tests/test_terminal_formatter.py b/tests/test_terminal_formatter.py index 1f44807d..91ad8937 100644 --- a/tests/test_terminal_formatter.py +++ b/tests/test_terminal_formatter.py @@ -3,13 +3,12 @@ Pygments terminal formatter tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ from __future__ import print_function -import unittest import re from pygments.util import StringIO @@ -37,26 +36,26 @@ def strip_ansi(x): return ANSI_RE.sub('', x) -class TerminalFormatterTest(unittest.TestCase): - def test_reasonable_output(self): - out = StringIO() - TerminalFormatter().format(DEMO_TOKENS, out) - plain = strip_ansi(out.getvalue()) - self.assertEqual(DEMO_TEXT.count('\n'), plain.count('\n')) - print(repr(plain)) +def test_reasonable_output(): + out = StringIO() + TerminalFormatter().format(DEMO_TOKENS, out) + plain = strip_ansi(out.getvalue()) + assert DEMO_TEXT.count('\n') == plain.count('\n') + print(repr(plain)) - for a, b in zip(DEMO_TEXT.splitlines(), plain.splitlines()): - self.assertEqual(a, b) + for a, b in zip(DEMO_TEXT.splitlines(), plain.splitlines()): + assert a == b - def test_reasonable_output_lineno(self): - out = StringIO() - TerminalFormatter(linenos=True).format(DEMO_TOKENS, out) - plain = strip_ansi(out.getvalue()) - self.assertEqual(DEMO_TEXT.count('\n') + 1, plain.count('\n')) - print(repr(plain)) - for a, b in zip(DEMO_TEXT.splitlines(), plain.splitlines()): - self.assertTrue(a in b) +def test_reasonable_output_lineno(): + out = StringIO() + TerminalFormatter(linenos=True).format(DEMO_TOKENS, out) + plain = strip_ansi(out.getvalue()) + assert DEMO_TEXT.count('\n') + 1 == plain.count('\n') + print(repr(plain)) + + for a, b in zip(DEMO_TEXT.splitlines(), plain.splitlines()): + assert a in b class MyStyle(Style): @@ -68,8 +67,7 @@ class MyStyle(Style): } -class Terminal256FormatterTest(unittest.TestCase): - code = ''' +CODE = ''' # this should be a comment print("Hello World") async def function(a,b,c, *d, **kwarg:Bool)->Bool: @@ -78,25 +76,27 @@ async def function(a,b,c, *d, **kwarg:Bool)->Bool: ''' - def test_style_html(self): - style = HtmlFormatter(style=MyStyle).get_style_defs() - self.assertTrue('#555555' in style, - "ansigray for comment not html css style") - - def test_others_work(self): - """check other formatters don't crash""" - highlight(self.code, Python3Lexer(), LatexFormatter(style=MyStyle)) - highlight(self.code, Python3Lexer(), HtmlFormatter(style=MyStyle)) - - def test_256esc_seq(self): - """ - test that a few escape sequences are actualy used when using ansi<> color codes - """ - def termtest(x): - return highlight(x, Python3Lexer(), - Terminal256Formatter(style=MyStyle)) - - self.assertTrue('32;41' in termtest('0x123')) - self.assertTrue('32;42' in termtest('123')) - self.assertTrue('30;01' in termtest('#comment')) - self.assertTrue('34;41' in termtest('"String"')) + +def test_style_html(): + style = HtmlFormatter(style=MyStyle).get_style_defs() + assert '#555555' in style, "ansigray for comment not html css style" + + +def test_others_work(): + """check other formatters don't crash""" + highlight(CODE, Python3Lexer(), LatexFormatter(style=MyStyle)) + highlight(CODE, Python3Lexer(), HtmlFormatter(style=MyStyle)) + + +def test_256esc_seq(): + """ + test that a few escape sequences are actualy used when using ansi<> color codes + """ + def termtest(x): + return highlight(x, Python3Lexer(), + Terminal256Formatter(style=MyStyle)) + + assert '32;41' in termtest('0x123') + assert '32;42' in termtest('123') + assert '30;01' in termtest('#comment') + assert '34;41' in termtest('"String"') |