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 <russ...@ovn.org> --- 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 16b3fae..6750481 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 73c3048..4e87dbb 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 ec029fc..9ba7023 100644 --- a/tests/unixctl-py.at +++ b/tests/unixctl-py.at @@ -114,15 +114,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.5.0 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev