summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-10-07 16:36:28 +0200
committerGeorg Brandl <georg@python.org>2014-10-07 16:36:28 +0200
commitc4ab8b3b31e240e4575a7034e166b9d8140c9e2b (patch)
treec95b9f6c00435ea4482ea80b2110946e39a9a3ed
parentb8100205450bf23cca7efdf569112391e355ee35 (diff)
downloadpygments-c4ab8b3b31e240e4575a7034e166b9d8140c9e2b.tar.gz
Closes #908: fix test suite to test formatters with no Unicode output correctly.
-rw-r--r--tests/test_basic_api.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py
index e0df3447..32d675b6 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 text_type, StringIO, xrange, ClassNotFound
+from pygments.util import text_type, StringIO, BytesIO, xrange, ClassNotFound
import support
@@ -154,7 +154,8 @@ def test_get_lexers():
def test_formatter_public_api():
# test that every formatter class has the correct public API
ts = list(lexers.PythonLexer().get_tokens("def f(): pass"))
- out = StringIO()
+ string_out = StringIO()
+ bytes_out = BytesIO()
def verify(formatter):
info = formatters.FORMATTERS[formatter.__name__]
@@ -163,20 +164,21 @@ def test_formatter_public_api():
assert info[2], "missing formatter aliases"
assert info[4], "missing formatter docstring"
- if formatter.name == 'Raw tokens':
- # will not work with Unicode output file
- return
-
try:
inst = formatter(opt1="val1")
except (ImportError, FontNotFound):
raise support.SkipTest
+
try:
inst.get_style_defs()
except NotImplementedError:
# may be raised by formatters for which it doesn't make sense
pass
- inst.format(ts, out)
+
+ if formatter.unicodeoutput:
+ inst.format(ts, string_out)
+ else:
+ inst.format(ts, bytes_out)
for name in formatters.FORMATTERS:
formatter = getattr(formatters, name)