From 6d673bd2be38d271f964b33d8ac362c8f5a2af8f Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Thu, 1 Aug 2019 13:36:37 -0400 Subject: [PATCH] Fix commandline test character encoding issues for Py3 --- tests/test_cmdline.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 333965f..8e3df0f 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -54,11 +54,6 @@ def setup_module(): def teardown_module(): server_stop() -# Add an encoding property to StringIO so Python will convert Unicode -# properly when writing or reading. -class UTF8StringIO(io.StringIO): - encoding = 'utf-8' - class TestCmdline(object): def run(self, arg_string, infile=None, outfile=None): @@ -76,22 +71,20 @@ class TestCmdline(object): ( sys.stdin, sys.stdout, sys.stderr ) = self.saved # Empty input if none provided if infile is None: - infile = UTF8StringIO("") + infile = io.StringIO("") # Capture stderr - errfile = UTF8StringIO() + errfile = io.StringIO() if outfile is None: # If no output file, capture stdout with stderr outfile = errfile with stdio_wrapper(infile, outfile, errfile) as s: try: - # shlex doesn't support Unicode very well. Encode the - # string as UTF-8 explicitly before splitting. - args = shlex.split(arg_string.encode('utf-8')) + args = shlex.split(arg_string) nilmdb.cmdline.Cmdline(args).run() sys.exit(0) except SystemExit as e: exitcode = e.code - captured = nilmdb.utils.str.decode(outfile.getvalue()) + captured = outfile.getvalue() self.captured = captured self.exitcode = exitcode