tests: Deal with Python output differences.
authorRussell Bryant <russell@ovn.org>
Thu, 17 Dec 2015 17:22:31 +0000 (12:22 -0500)
committerRussell Bryant <russell@ovn.org>
Mon, 22 Feb 2016 20:17:23 +0000 (15:17 -0500)
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 <russell@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
tests/test-json.py
tests/test-ovsdb.py
tests/unixctl-py.at

index 16b3fae..6750481 100644 (file)
@@ -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'])
index 73c3048..4e87dbb 100644 (file)
@@ -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):
index 4838d2d..3a56163 100644 (file)
@@ -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