diff options
author | Georg Brandl <georg@python.org> | 2014-10-08 01:20:11 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-08 01:20:11 +0200 |
commit | 484583e428efde3dbea4980ffeafc53d4fe37935 (patch) | |
tree | 4102a9b4462a6069eb55bff5009a52e8e35f2314 /tests | |
parent | c0ffb8a5babc8e6d1c58b92810f1cc11ae96ff85 (diff) | |
download | pygments-484583e428efde3dbea4980ffeafc53d4fe37935.tar.gz |
Overhaul encoding handling in cmdline even more.
Now the encoding guessed for the input file will be used for an output file.
We now always read and write to the terminal .buffer on Python 3, which allows
us to override the terminal encoding and use our guessing algorithm.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmdline.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index e4953f7e..9e26ce17 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -7,14 +7,14 @@ :license: BSD, see LICENSE for details. """ -# Test the command line interface +from __future__ import print_function import io import sys import unittest from pygments import highlight -from pygments.util import StringIO +from pygments.util import StringIO, BytesIO from pygments.cmdline import main as cmdline_main import support @@ -25,14 +25,24 @@ TESTFILE, TESTDIR = support.location(__file__) def run_cmdline(*args): saved_stdout = sys.stdout saved_stderr = sys.stderr - new_stdout = sys.stdout = StringIO() - new_stderr = sys.stderr = StringIO() + if sys.version_info > (3,): + stdout_buffer = BytesIO() + stderr_buffer = BytesIO() + new_stdout = sys.stdout = io.TextIOWrapper(stdout_buffer) + new_stderr = sys.stderr = io.TextIOWrapper(stderr_buffer) + else: + stdout_buffer = new_stdout = sys.stdout = StringIO() + stderr_buffer = new_stderr = sys.stderr = 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()) + new_stdout.flush() + new_stderr.flush() + out, err = stdout_buffer.getvalue().decode('utf-8'), \ + stderr_buffer.getvalue().decode('utf-8') + return (ret, out, err) class CmdLineTest(unittest.TestCase): @@ -83,7 +93,7 @@ class CmdLineTest(unittest.TestCase): def test_invalid_opts(self): for opts in [("-L", "-lpy"), ("-L", "-fhtml"), ("-L", "-Ox"), ("-a",), ("-Sst", "-lpy"), ("-H",), - ("-H", "formatter"),]: + ("-H", "formatter")]: self.assertTrue(run_cmdline(*opts)[0] == 2) def test_normal(self): |