summaryrefslogtreecommitdiff
path: root/tests/test_basic_api.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-10-07 16:29:05 +0200
committerGeorg Brandl <georg@python.org>2014-10-07 16:29:05 +0200
commitb8100205450bf23cca7efdf569112391e355ee35 (patch)
tree88d2ab792377fec5506d186e60f2e5e6e89cd820 /tests/test_basic_api.py
parenta6cf012f0d3eb16412e9aad23c44e4a8309f22f1 (diff)
downloadpygments-b8100205450bf23cca7efdf569112391e355ee35.tar.gz
Closes #1028: fix filters to return Unicode strings
Diffstat (limited to 'tests/test_basic_api.py')
-rw-r--r--tests/test_basic_api.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index 0beb0171..e0df3447 100644
--- a/tests/test_basic_api.py
+++ b/tests/test_basic_api.py
@@ -257,18 +257,27 @@ def test_styles():
class FiltersTest(unittest.TestCase):
def test_basic(self):
- filter_args = {
- 'whitespace': {'spaces': True, 'tabs': True, 'newlines': True},
- 'highlight': {'names': ['isinstance', 'lexers', 'x']},
- }
- for x in filters.FILTERS:
+ filters_args = [
+ ('whitespace', {'spaces': True, 'tabs': True, 'newlines': True}),
+ ('whitespace', {'wstokentype': False, 'spaces': True}),
+ ('highlight', {'names': ['isinstance', 'lexers', 'x']}),
+ ('codetagify', {'codetags': 'API'}),
+ ('keywordcase', {'case': 'capitalize'}),
+ ('raiseonerror', {}),
+ ('gobble', {'n': 4}),
+ ('tokenmerge', {}),
+ ]
+ for x, args in filters_args:
lx = lexers.PythonLexer()
- lx.add_filter(x, **filter_args.get(x, {}))
+ lx.add_filter(x, **args)
with open(TESTFILE, 'rb') as fp:
text = fp.read().decode('utf-8')
tokens = list(lx.get_tokens(text))
+ self.assertTrue(all(isinstance(t[1], text_type)
+ for t in tokens),
+ '%s filter did not return Unicode' % x)
roundtext = ''.join([t[1] for t in tokens])
- if x not in ('whitespace', 'keywordcase'):
+ if x not in ('whitespace', 'keywordcase', 'gobble'):
# these filters change the text
self.assertEqual(roundtext, text,
"lexer roundtrip with %s filter failed" % x)