From 64eb96a9af0917a4c7b8e0441d2e49404fd247d5 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 17 Dec 2015 12:22:31 -0500 Subject: [PATCH] tests: Deal with Python output differences. This test checks the output based on Python's string representation of an array of two unicode strings. These strings have a "u" prefix in Python 2, but not Python 3. In Python 3, all strings are unicode. Use sed on the output to strip the "u" from Python 2 output when checking for the expected result. Signed-off-by: Russell Bryant Acked-by: Ben Pfaff --- tests/test-json.py | 8 +++++--- tests/test-ovsdb.py | 2 +- tests/unixctl-py.at | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/test-json.py b/tests/test-json.py index 16b3fae5d..6750481e8 100644 --- a/tests/test-json.py +++ b/tests/test-json.py @@ -58,9 +58,11 @@ def parse_multiple(stream): def main(argv): argv0 = argv[0] - # Make stdout and stderr UTF-8, even if they are redirected to a file. - sys.stdout = codecs.getwriter("utf-8")(sys.stdout) - sys.stderr = codecs.getwriter("utf-8")(sys.stderr) + # When this is used with Python 3, the program produces no output. + if sys.version_info[0] == 2: + # Make stdout and stderr UTF-8, even if they are redirected to a file. + sys.stdout = codecs.getwriter("utf-8")(sys.stdout) + sys.stderr = codecs.getwriter("utf-8")(sys.stderr) try: options, args = getopt.gnu_getopt(argv[1:], '', ['multiple']) diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py index 73c30488f..4e87dbb4c 100644 --- a/tests/test-ovsdb.py +++ b/tests/test-ovsdb.py @@ -109,7 +109,7 @@ def do_parse_atoms(type_string, *atom_strings): atom = data.Atom.from_json(base, atom_json) print(ovs.json.to_string(atom.to_json())) except error.Error as e: - print(e.args[0].encode("utf8")) + print(e.args[0]) def do_parse_data(type_string, *data_strings): diff --git a/tests/unixctl-py.at b/tests/unixctl-py.at index 4838d2db5..3a561632a 100644 --- a/tests/unixctl-py.at +++ b/tests/unixctl-py.at @@ -115,15 +115,15 @@ AT_CHECK([APPCTL -t test-unixctl.py version], [0], [expout]) AT_CHECK([PYAPPCTL -t test-unixctl.py version], [0], [expout]) AT_CHECK([APPCTL -t test-unixctl.py echo robot ninja], [0], [stdout]) -AT_CHECK([cat stdout], [0], [dnl -[[u'robot', u'ninja']] +AT_CHECK([cat stdout | sed -e "s/u'/'/g"], [0], [dnl +[['robot', 'ninja']] ]) mv stdout expout AT_CHECK([PYAPPCTL -t test-unixctl.py echo robot ninja], [0], [expout]) AT_CHECK([APPCTL -t test-unixctl.py echo_error robot ninja], [2], [], [stderr]) -AT_CHECK([cat stderr], [0], [dnl -[[u'robot', u'ninja']] +AT_CHECK([cat stderr | sed -e "s/u'/'/g"], [0], [dnl +[['robot', 'ninja']] ovs-appctl: test-unixctl.py: server returned an error ]) sed 's/ovs-appctl/appctl.py/' stderr > experr -- 2.20.1