From patchwork Tue Feb 2 22:36:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Bryant X-Patchwork-Id: 577623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 93BAD140556 for ; Wed, 3 Feb 2016 09:37:13 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 0BA6410AD2; Tue, 2 Feb 2016 14:37:10 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id D7C0010AC9 for ; Tue, 2 Feb 2016 14:37:08 -0800 (PST) Received: from bar4.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 25771163450 for ; Tue, 2 Feb 2016 15:37:08 -0700 (MST) X-ASG-Debug-ID: 1454452627-03dc217d9b10ccb10001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar4.cudamail.com with ESMTP id 9A7PFYjgYsLre2zb (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 02 Feb 2016 15:37:07 -0700 (MST) X-Barracuda-Envelope-From: russell@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 2 Feb 2016 22:37:07 -0000 Received-SPF: neutral (mx1-pf1.cudamail.com: 209.132.183.28 is neither permitted nor denied by SPF record at ovn.org) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 3DA0DE1B93; Tue, 2 Feb 2016 22:37:06 +0000 (UTC) Received: from x1c.redhat.com (ovpn-112-49.phx2.redhat.com [10.3.112.49]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u12Mb383017731; Tue, 2 Feb 2016 17:37:05 -0500 X-CudaMail-Envelope-Sender: russell@ovn.org From: Russell Bryant To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-201093462 X-CudaMail-DTE: 020216 X-CudaMail-Originating-IP: 209.132.183.28 Date: Tue, 2 Feb 2016 17:36:43 -0500 X-ASG-Orig-Subj: [##CM-E1-201093462##][PATCH 01/14] tests: Deal with Python output differences. Message-Id: <1454452616-8135-2-git-send-email-russell@ovn.org> In-Reply-To: <1454452616-8135-1-git-send-email-russell@ovn.org> References: <1454452616-8135-1-git-send-email-russell@ovn.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1454452627 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 01/14] tests: Deal with Python output differences. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" 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 --- 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