From f73c52a87b995806b4462a425a9f589031c57e9b Mon Sep 17 00:00:00 2001 From: Thomas Aglassinger Date: Sun, 2 Jun 2013 14:12:38 +0000 Subject: Simplified debugging of endless loops in lexers with random generated content. If the developer terminates the test by pressing Control-C, the resulting KeyboardInterrupt describes the lexer and content that caused the test to get stuck. --- tests/test_basic_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/test_basic_api.py') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 18ed8d64..9ec6e928 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -60,7 +60,10 @@ def test_lexer_classes(): if cls.name in ['XQuery', 'Opa']: # XXX temporary return - tokens = list(inst.get_tokens(test_content)) + try: + tokens = list(inst.get_tokens(test_content)) + except KeyboardInterrupt: + raise KeyboardInterrupt('interrupted %s.get_tokens(): test_content=%r' % (cls.name, test_content)) txt = "" for token in tokens: assert isinstance(token, tuple) -- cgit v1.2.1 From 406a7c5ef7266419b4858e94cfa59f2e9f612de1 Mon Sep 17 00:00:00 2001 From: Thomas Aglassinger Date: Sun, 2 Jun 2013 14:17:35 +0000 Subject: Changed error message to use lexer class instead of lexer name. --- tests/test_basic_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_basic_api.py') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 9ec6e928..19e1988b 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -63,7 +63,7 @@ def test_lexer_classes(): try: tokens = list(inst.get_tokens(test_content)) except KeyboardInterrupt: - raise KeyboardInterrupt('interrupted %s.get_tokens(): test_content=%r' % (cls.name, test_content)) + raise KeyboardInterrupt('interrupted %s.get_tokens(): test_content=%r' % (cls.__name__, test_content)) txt = "" for token in tokens: assert isinstance(token, tuple) -- cgit v1.2.1 From d2f5bd0e335d7ab8d6bee65cab8869a83624e2e3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 9 Jan 2014 20:24:06 +0100 Subject: tests: make sure lexer aliases are registered lowercase --- tests/test_basic_api.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_basic_api.py') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 19e1988b..d1422a5c 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -45,6 +45,8 @@ def test_lexer_classes(): result = cls.analyse_text(".abc") assert isinstance(result, float) and 0.0 <= result <= 1.0 + assert all(al.lower() == al for al in cls.aliases) + inst = cls(opt1="val1", opt2="val2") if issubclass(cls, RegexLexer): if not hasattr(cls, '_tokens'): -- cgit v1.2.1 From 492f361b79f93a110679ccb7f7e86f4814990dee Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 10 Jan 2014 10:52:53 +0100 Subject: new year in copyright notice --- tests/test_basic_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_basic_api.py') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index d1422a5c..1c6933a7 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -3,7 +3,7 @@ Pygments basic API tests ~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -- cgit v1.2.1 From a9169c157a05c82a1b8a7ffb92e7f159fb4ca0f8 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 18 Jan 2014 13:25:15 +0100 Subject: futurizing: move to print_function and "except X as Y" syntax --- tests/test_basic_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/test_basic_api.py') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 1c6933a7..ecf45d84 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -6,6 +6,7 @@ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import print_function import os import random @@ -71,7 +72,7 @@ def test_lexer_classes(): assert isinstance(token, tuple) assert isinstance(token[0], _TokenType) if isinstance(token[1], str): - print repr(token[1]) + print(repr(token[1])) assert isinstance(token[1], unicode) txt += token[1] assert txt == test_content, "%s lexer roundtrip failed: %r != %r" % \ -- cgit v1.2.1 From b6b690fb833e7031a3008509c1107f7567c065f3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 18 Jan 2014 13:29:19 +0100 Subject: manual prettifying and small fixes after futurize run --- tests/test_basic_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_basic_api.py') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index ecf45d84..5a7bb42f 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -6,9 +6,9 @@ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ + from __future__ import print_function -import os import random import unittest @@ -16,7 +16,7 @@ from pygments import lexers, formatters, filters, format from pygments.token import _TokenType, Text from pygments.lexer import RegexLexer from pygments.formatters.img import FontNotFound -from pygments.util import BytesIO, StringIO, bytes, b +from pygments.util import StringIO, bytes import support -- cgit v1.2.1 From 97703d63f39e6086d497a6a749c9eee3293dcbeb Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 18 Jan 2014 16:44:49 +0100 Subject: Finalize single-source port for Py2.[67] and Py3.3+. --- tests/test_basic_api.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/test_basic_api.py') diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index 5a7bb42f..78227d2f 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -16,7 +16,7 @@ from pygments import lexers, formatters, filters, format from pygments.token import _TokenType, Text from pygments.lexer import RegexLexer from pygments.formatters.img import FontNotFound -from pygments.util import StringIO, bytes +from pygments.util import text_type, StringIO, xrange import support @@ -29,7 +29,7 @@ test_content = ''.join(test_content) + '\n' def test_lexer_import_all(): # instantiate every lexer, to see if the token type defs are correct - for x in lexers.LEXERS.keys(): + for x in lexers.LEXERS: c = getattr(lexers, x)() @@ -73,7 +73,7 @@ def test_lexer_classes(): assert isinstance(token[0], _TokenType) if isinstance(token[1], str): print(repr(token[1])) - assert isinstance(token[1], unicode) + assert isinstance(token[1], text_type) txt += token[1] assert txt == test_content, "%s lexer roundtrip failed: %r != %r" % \ (cls.name, test_content, txt) @@ -128,7 +128,7 @@ def test_get_lexers(): ]: yield verify, func, args - for cls, (_, lname, aliases, _, mimetypes) in lexers.LEXERS.iteritems(): + for cls, (_, lname, aliases, _, mimetypes) in lexers.LEXERS.items(): assert cls == lexers.find_lexer_class(lname).__name__ for alias in aliases: @@ -163,7 +163,7 @@ def test_formatter_public_api(): pass inst.format(ts, out) - for formatter, info in formatters.FORMATTERS.iteritems(): + for formatter, info in formatters.FORMATTERS.items(): yield verify, formatter, info def test_formatter_encodings(): @@ -173,7 +173,7 @@ def test_formatter_encodings(): fmt = HtmlFormatter() tokens = [(Text, u"ä")] out = format(tokens, fmt) - assert type(out) is unicode + assert type(out) is text_type assert u"ä" in out # encoding option @@ -202,7 +202,7 @@ def test_formatter_unicode_handling(): if formatter.name != 'Raw tokens': out = format(tokens, inst) if formatter.unicodeoutput: - assert type(out) is unicode + assert type(out) is text_type inst = formatter(encoding='utf-8') out = format(tokens, inst) @@ -214,7 +214,7 @@ def test_formatter_unicode_handling(): out = format(tokens, inst) assert type(out) is bytes, '%s: %r' % (formatter, out) - for formatter, info in formatters.FORMATTERS.iteritems(): + for formatter, info in formatters.FORMATTERS.items(): yield verify, formatter @@ -242,7 +242,7 @@ class FiltersTest(unittest.TestCase): 'whitespace': {'spaces': True, 'tabs': True, 'newlines': True}, 'highlight': {'names': ['isinstance', 'lexers', 'x']}, } - for x in filters.FILTERS.keys(): + for x in filters.FILTERS: lx = lexers.PythonLexer() lx.add_filter(x, **filter_args.get(x, {})) fp = open(TESTFILE, 'rb') -- cgit v1.2.1