From patchwork Mon Dec 21 20:47:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Bryant X-Patchwork-Id: 559729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 513C7140BB2 for ; Tue, 22 Dec 2015 07:54:20 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id F077B10882; Mon, 21 Dec 2015 12:48:40 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 11B7010875 for ; Mon, 21 Dec 2015 12:48:39 -0800 (PST) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 932E142007F for ; Mon, 21 Dec 2015 13:48:38 -0700 (MST) X-ASG-Debug-ID: 1450730918-09eadd632cc67b0001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id xiFpdLz4rYaDsP0S (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 21 Dec 2015 13:48:38 -0700 (MST) X-Barracuda-Envelope-From: russell@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 21 Dec 2015 20:48:37 -0000 Received-SPF: neutral (mx1-pf2.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 3912C219D; Mon, 21 Dec 2015 20:48:37 +0000 (UTC) Received: from x1c.redhat.com ([10.3.112.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBLKm0dt002018; Mon, 21 Dec 2015 15:48:36 -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-E2-1220082830 X-CudaMail-DTE: 122115 X-CudaMail-Originating-IP: 209.132.183.28 Date: Mon, 21 Dec 2015 15:47:32 -0500 X-ASG-Orig-Subj: [##CM-E2-1220082830##][PATCH 32/55] tests: Python style fixes. Message-Id: <1450730875-18083-33-git-send-email-russell@ovn.org> In-Reply-To: <1450730875-18083-1-git-send-email-russell@ovn.org> References: <1450730875-18083-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.2] X-Barracuda-Start-Time: 1450730918 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 32/55] tests: Python style fixes. 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" Make flake8 run clean against these. Also use isinstance() instead of direct type comparisons. Update the tox config to run flake8 against these files, as well. Signed-off-by: Russell Bryant --- python/tox.ini | 2 +- tests/MockXenAPI.py | 3 +++ tests/test-daemon.py | 1 - tests/test-jsonrpc.py | 4 ++-- tests/test-l7.py | 2 +- tests/test-ovsdb.py | 48 +++++++++++++++++++++++------------------------ tests/test-reconnect.py | 4 ++-- tests/test-unix-socket.py | 1 + tests/test-unixctl.py | 3 ++- 9 files changed, 36 insertions(+), 32 deletions(-) diff --git a/python/tox.ini b/python/tox.ini index d5422f8..4e55e62 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -14,7 +14,7 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt [testenv:pep8] -commands = flake8 +commands = flake8 --exclude="*testsuite.dir*" ovs/ ovstest/ {toxinidir}/../tests/ [flake8] ignore=E111,E113,E126,E127,E128,E129,E131 diff --git a/tests/MockXenAPI.py b/tests/MockXenAPI.py index cca1571..b8de4ee 100644 --- a/tests/MockXenAPI.py +++ b/tests/MockXenAPI.py @@ -14,6 +14,7 @@ import re + def xapi_local(): return Session() @@ -97,6 +98,7 @@ class Pool(Table): def __init__(self): Table.__init__(self, Pool.__records) + class VIF(Table): __records = ({"uuid": "6ab1b260-398e-49ba-827b-c7696108964c", "other_config": @@ -105,6 +107,7 @@ class VIF(Table): def __init__(self): Table.__init__(self, VIF.__records) + class VM(Table): __records = ({"uuid": "fcb8a3f6-dc04-41d2-8b8a-55afd2b755b8", "other_config": diff --git a/tests/test-daemon.py b/tests/test-daemon.py index b759cf9..63c1f70 100644 --- a/tests/test-daemon.py +++ b/tests/test-daemon.py @@ -13,7 +13,6 @@ # limitations under the License. import argparse -import logging import signal import sys import time diff --git a/tests/test-jsonrpc.py b/tests/test-jsonrpc.py index fc12caf..18634e6 100644 --- a/tests/test-jsonrpc.py +++ b/tests/test-jsonrpc.py @@ -88,7 +88,7 @@ def do_listen(name): if error: rpc.close() dead_rpcs.append(rpc) - rpcs = [rpc for rpc in rpcs if not rpc in dead_rpcs] + rpcs = [rpc for rpc in rpcs if rpc not in dead_rpcs] if done and not rpcs: break @@ -189,7 +189,7 @@ notify REMOTE METHOD PARAMS send notification and exit command_name = args.command[0] args = args.command_args - if not command_name in commands: + if command_name not in commands: sys.stderr.write("%s: unknown command \"%s\" " "(use --help for help)\n" % (argv[0], command_name)) sys.exit(1) diff --git a/tests/test-l7.py b/tests/test-l7.py index d15a167..66e05a1 100755 --- a/tests/test-l7.py +++ b/tests/test-l7.py @@ -50,7 +50,7 @@ def get_ftpd(): def main(): SERVERS = { - 'http': [TCPServer, SimpleHTTPRequestHandler, 80], + 'http': [TCPServer, SimpleHTTPRequestHandler, 80], 'http6': [TCPServerV6, SimpleHTTPRequestHandler, 80], } diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py index 8528f33..9d18ec3 100644 --- a/tests/test-ovsdb.py +++ b/tests/test-ovsdb.py @@ -25,7 +25,7 @@ from ovs.db import error import ovs.db.idl import ovs.db.schema from ovs.db import data -from ovs.db import types +import ovs.db.types import ovs.ovsuuid import ovs.poller import ovs.util @@ -33,15 +33,15 @@ import six def unbox_json(json): - if type(json) == list and len(json) == 1: + if isinstance(json, list) and len(json) == 1: return json[0] else: return json def do_default_atoms(): - for type_ in types.ATOMIC_TYPES: - if type_ == types.VoidType: + for type_ in ovs.db.types.ATOMIC_TYPES: + if type_ == ovs.db.types.VoidType: continue sys.stdout.write("%s: " % type_.to_string()) @@ -57,15 +57,16 @@ def do_default_atoms(): def do_default_data(): any_errors = False for n_min in 0, 1: - for key in types.ATOMIC_TYPES: - if key == types.VoidType: + for key in ovs.db.types.ATOMIC_TYPES: + if key == ovs.db.types.VoidType: continue - for value in types.ATOMIC_TYPES: - if value == types.VoidType: + for value in ovs.db.types.ATOMIC_TYPES: + if value == ovs.db.types.VoidType: valueBase = None else: - valueBase = types.BaseType(value) - type_ = types.Type(types.BaseType(key), valueBase, n_min, 1) + valueBase = ovs.db.types.BaseType(value) + type_ = ovs.db.types.Type(ovs.db.types.BaseType(key), + valueBase, n_min, 1) assert type_.is_valid() sys.stdout.write("key %s, value %s, n_min %d: " @@ -83,25 +84,25 @@ def do_default_data(): def do_parse_atomic_type(type_string): type_json = unbox_json(ovs.json.from_string(type_string)) - atomic_type = types.AtomicType.from_json(type_json) + atomic_type = ovs.db.types.AtomicType.from_json(type_json) print(ovs.json.to_string(atomic_type.to_json(), sort_keys=True)) def do_parse_base_type(type_string): type_json = unbox_json(ovs.json.from_string(type_string)) - base_type = types.BaseType.from_json(type_json) + base_type = ovs.db.types.BaseType.from_json(type_json) print(ovs.json.to_string(base_type.to_json(), sort_keys=True)) def do_parse_type(type_string): type_json = unbox_json(ovs.json.from_string(type_string)) - type_ = types.Type.from_json(type_json) + type_ = ovs.db.types.Type.from_json(type_json) print(ovs.json.to_string(type_.to_json(), sort_keys=True)) def do_parse_atoms(type_string, *atom_strings): type_json = unbox_json(ovs.json.from_string(type_string)) - base = types.BaseType.from_json(type_json) + base = ovs.db.types.BaseType.from_json(type_json) for atom_string in atom_strings: atom_json = unbox_json(ovs.json.from_string(atom_string)) try: @@ -113,7 +114,7 @@ def do_parse_atoms(type_string, *atom_strings): def do_parse_data(type_string, *data_strings): type_json = unbox_json(ovs.json.from_string(type_string)) - type_ = types.Type.from_json(type_json) + type_ = ovs.db.types.Type.from_json(type_json) for datum_string in data_strings: datum_json = unbox_json(ovs.json.from_string(datum_string)) datum = data.Datum.from_json(type_, datum_json) @@ -122,7 +123,7 @@ def do_parse_data(type_string, *data_strings): def do_sort_atoms(type_string, atom_strings): type_json = unbox_json(ovs.json.from_string(type_string)) - base = types.BaseType.from_json(type_json) + base = ovs.db.types.BaseType.from_json(type_json) atoms = [data.Atom.from_json(base, atom_json) for atom_json in unbox_json(ovs.json.from_string(atom_strings))] print(ovs.json.to_string([data.Atom.to_json(atom) @@ -207,9 +208,9 @@ def substitute_uuids(json, symtab): symbol = symtab.get(json) if symbol: return str(symbol) - elif type(json) == list: + elif isinstance(json, list): return [substitute_uuids(element, symtab) for element in json] - elif type(json) == dict: + elif isinstance(json, dict): d = {} for key, value in six.iteritems(json): d[key] = substitute_uuids(value, symtab) @@ -223,10 +224,10 @@ def parse_uuids(json, symtab): name = "#%d#" % len(symtab) sys.stderr.write("%s = %s\n" % (name, json)) symtab[name] = json - elif type(json) == list: + elif isinstance(json, list): for element in json: parse_uuids(element, symtab) - elif type(json) == dict: + elif isinstance(json, dict): for value in six.itervalues(json): parse_uuids(value, symtab) @@ -393,7 +394,6 @@ def idl_set(idl, commands, step): def do_idl(schema_file, remote, *commands): schema_helper = ovs.db.idl.SchemaHelper(schema_file) if commands and commands[0].startswith("?"): - monitor = {} readonly = {} for x in commands[0][1:].split("?"): readonly = [] @@ -591,21 +591,21 @@ def main(argv): command_name = args[0] args = args[1:] - if not command_name in commands: + if command_name not in commands: sys.stderr.write("%s: unknown command \"%s\" " "(use --help for help)\n" % (ovs.util.PROGRAM_NAME, command_name)) sys.exit(1) func, n_args = commands[command_name] - if type(n_args) == tuple: + if isinstance(n_args, tuple): if len(args) < n_args[0]: sys.stderr.write("%s: \"%s\" requires at least %d arguments but " "only %d provided\n" % (ovs.util.PROGRAM_NAME, command_name, n_args, len(args))) sys.exit(1) - elif type(n_args) == int: + elif isinstance(n_args, int): if len(args) != n_args: sys.stderr.write("%s: \"%s\" requires %d arguments but %d " "provided\n" diff --git a/tests/test-reconnect.py b/tests/test-reconnect.py index 10d97d1..4ff95ae 100644 --- a/tests/test-reconnect.py +++ b/tests/test-reconnect.py @@ -132,7 +132,7 @@ def diff_stats(old, new, delta): print((" %sconnected" % negate)) if (old.last_connected != new.last_connected or - (new.msec_since_connect != None and + (new.msec_since_connect is not None and old.msec_since_connect != new.msec_since_connect - delta) or (old.total_connected_duration != new.total_connected_duration - delta and not (old.total_connected_duration == 0 and @@ -141,7 +141,7 @@ def diff_stats(old, new, delta): % (new.msec_since_connect, new.total_connected_duration))) if (old.last_disconnected != new.last_disconnected or - (new.msec_since_disconnect != None and + (new.msec_since_disconnect is not None and old.msec_since_disconnect != new.msec_since_disconnect - delta)): print((" disconnected at %d ms (%d ms ago)" % (new.last_disconnected, new.msec_since_disconnect))) diff --git a/tests/test-unix-socket.py b/tests/test-unix-socket.py index f55f6c3..aac32bd 100644 --- a/tests/test-unix-socket.py +++ b/tests/test-unix-socket.py @@ -20,6 +20,7 @@ import sys import ovs.socket_util + def main(argv): if len(argv) not in (2, 3): sys.stderr.write("usage: %s SOCKETNAME1 [SOCKETNAME2]", argv[0]) diff --git a/tests/test-unixctl.py b/tests/test-unixctl.py index ab03479..5de51d3 100644 --- a/tests/test-unixctl.py +++ b/tests/test-unixctl.py @@ -22,6 +22,7 @@ import ovs.unixctl.server vlog = ovs.vlog.Vlog("test-unixctl") exiting = False + def unixctl_exit(conn, unused_argv, aux): assert aux == "aux_exit" global exiting @@ -36,7 +37,7 @@ def unixctl_echo(conn, argv, aux): def unixctl_echo_error(conn, argv, aux): - assert aux == "aux_echo_error" + assert aux == "aux_echo_error" conn.reply_error(str(argv))