From f3bbf52b3c7e731796aaf38294d08109859babe5 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Sat, 15 Jul 2017 16:58:08 +0000 Subject: [PATCH] Use flake8-import-order plugin In reviews we usually check import grouping but it is boring. By using flake8-import-order plugin, we can avoid this. It enforces loose checking so it sounds good to use it. This flake8 plugin is already used in tempest. Note that flake8-import-order version is pinned to avoid unexpected breakage of pep8 job. Setup for unit tests of hacking rules is tweaked to disable flake8-import-order checks. This extension assumes an actual file exists and causes hacking rule unit tests. Change-Id: I12b596820727aeeb379bee16c2bc993dee9eb637 --- openstackclient/common/clientmanager.py | 2 +- openstackclient/compute/v2/server_event.py | 2 +- openstackclient/tests/functional/base.py | 2 +- openstackclient/tests/unit/common/test_logs.py | 1 + openstackclient/tests/unit/common/test_quota.py | 2 +- openstackclient/tests/unit/compute/v2/fakes.py | 3 ++- openstackclient/tests/unit/compute/v2/test_keypair.py | 4 ++-- openstackclient/tests/unit/compute/v2/test_server.py | 2 +- openstackclient/tests/unit/compute/v2/test_usage.py | 1 + openstackclient/tests/unit/fakes.py | 2 +- openstackclient/tests/unit/identity/v2_0/fakes.py | 2 +- .../tests/unit/identity/v2_0/test_role_assignment.py | 2 +- openstackclient/tests/unit/identity/v3/fakes.py | 2 +- .../tests/unit/identity/v3/test_identity_provider.py | 1 + openstackclient/tests/unit/identity/v3/test_mappings.py | 2 +- openstackclient/tests/unit/identity/v3/test_role.py | 2 +- .../tests/unit/identity/v3/test_role_assignment.py | 1 + openstackclient/tests/unit/identity/v3/test_trust.py | 2 +- openstackclient/tests/unit/identity/v3/test_user.py | 2 +- openstackclient/tests/unit/image/v1/fakes.py | 3 ++- openstackclient/tests/unit/image/v1/test_image.py | 2 +- openstackclient/tests/unit/image/v2/fakes.py | 2 +- openstackclient/tests/unit/image/v2/test_image.py | 2 +- openstackclient/tests/unit/integ/cli/test_shell.py | 2 +- openstackclient/tests/unit/network/test_common.py | 1 + openstackclient/tests/unit/network/v2/fakes.py | 3 ++- openstackclient/tests/unit/network/v2/test_network.py | 4 ++-- openstackclient/tests/unit/network/v2/test_port.py | 2 +- openstackclient/tests/unit/network/v2/test_subnet_pool.py | 2 +- openstackclient/tests/unit/object/v1/test_container.py | 1 + openstackclient/tests/unit/object/v1/test_object.py | 1 + openstackclient/tests/unit/test_shell.py | 2 +- openstackclient/tests/unit/utils.py | 3 ++- openstackclient/tests/unit/volume/v1/fakes.py | 3 ++- openstackclient/tests/unit/volume/v1/test_qos_specs.py | 2 +- openstackclient/tests/unit/volume/v1/test_volume.py | 2 +- openstackclient/tests/unit/volume/v2/fakes.py | 2 +- openstackclient/tests/unit/volume/v2/test_qos_specs.py | 2 +- openstackclient/tests/unit/volume/v2/test_snapshot.py | 2 +- openstackclient/tests/unit/volume/v2/test_volume.py | 2 +- test-requirements.txt | 1 + tox.ini | 1 + 42 files changed, 49 insertions(+), 35 deletions(-) diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py index 67912f0cd0..ea581696c0 100644 --- a/openstackclient/common/clientmanager.py +++ b/openstackclient/common/clientmanager.py @@ -16,11 +16,11 @@ """Manage access to the clients, including authenticating when needed.""" import logging -import pkg_resources import sys from osc_lib import clientmanager from osc_lib import shell +import pkg_resources LOG = logging.getLogger(__name__) diff --git a/openstackclient/compute/v2/server_event.py b/openstackclient/compute/v2/server_event.py index ccb19ef722..d8fbda0f2d 100644 --- a/openstackclient/compute/v2/server_event.py +++ b/openstackclient/compute/v2/server_event.py @@ -16,10 +16,10 @@ """Compute v2 Server operation event implementations""" import logging -import six from osc_lib.command import command from osc_lib import utils +import six from openstackclient.i18n import _ diff --git a/openstackclient/tests/functional/base.py b/openstackclient/tests/functional/base.py index 4c88b13e93..90bbc24d29 100644 --- a/openstackclient/tests/functional/base.py +++ b/openstackclient/tests/functional/base.py @@ -14,10 +14,10 @@ import os import re import shlex import subprocess -import testtools from tempest.lib.cli import output_parser from tempest.lib import exceptions +import testtools COMMON_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/openstackclient/tests/unit/common/test_logs.py b/openstackclient/tests/unit/common/test_logs.py index 4842c8d45c..b1e4d61242 100644 --- a/openstackclient/tests/unit/common/test_logs.py +++ b/openstackclient/tests/unit/common/test_logs.py @@ -15,6 +15,7 @@ # or Jun 2017. import logging + import mock from openstackclient.common import logs diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py index 482653f460..1a3da31d78 100644 --- a/openstackclient/tests/unit/common/test_quota.py +++ b/openstackclient/tests/unit/common/test_quota.py @@ -11,8 +11,8 @@ # under the License. import copy -import mock +import mock from osc_lib import exceptions from openstackclient.common import quota diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py index d5fc9fa957..0fae19af8f 100644 --- a/openstackclient/tests/unit/compute/v2/fakes.py +++ b/openstackclient/tests/unit/compute/v2/fakes.py @@ -14,9 +14,10 @@ # import copy -import mock import uuid +import mock + from openstackclient.api import compute_v2 from openstackclient.tests.unit import fakes from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes diff --git a/openstackclient/tests/unit/compute/v2/test_keypair.py b/openstackclient/tests/unit/compute/v2/test_keypair.py index d6f5ecf457..0e5fb14324 100644 --- a/openstackclient/tests/unit/compute/v2/test_keypair.py +++ b/openstackclient/tests/unit/compute/v2/test_keypair.py @@ -13,10 +13,10 @@ # under the License. # -import mock -from mock import call import uuid +import mock +from mock import call from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 5b0d28a1c6..a1225c3004 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -15,9 +15,9 @@ import argparse import collections import getpass + import mock from mock import call - from osc_lib import exceptions from osc_lib import utils as common_utils from oslo_utils import timeutils diff --git a/openstackclient/tests/unit/compute/v2/test_usage.py b/openstackclient/tests/unit/compute/v2/test_usage.py index a383e9036d..a7aa1374e6 100644 --- a/openstackclient/tests/unit/compute/v2/test_usage.py +++ b/openstackclient/tests/unit/compute/v2/test_usage.py @@ -12,6 +12,7 @@ # import datetime + import mock from openstackclient.compute.v2 import usage diff --git a/openstackclient/tests/unit/fakes.py b/openstackclient/tests/unit/fakes.py index 999694b779..65c76b3e33 100644 --- a/openstackclient/tests/unit/fakes.py +++ b/openstackclient/tests/unit/fakes.py @@ -14,10 +14,10 @@ # import json -import mock import sys from keystoneauth1 import fixture +import mock import requests import six diff --git a/openstackclient/tests/unit/identity/v2_0/fakes.py b/openstackclient/tests/unit/identity/v2_0/fakes.py index 3d25cadfa6..5db9422275 100644 --- a/openstackclient/tests/unit/identity/v2_0/fakes.py +++ b/openstackclient/tests/unit/identity/v2_0/fakes.py @@ -14,11 +14,11 @@ # import copy -import mock import uuid from keystoneauth1 import access from keystoneauth1 import fixture +import mock from openstackclient.tests.unit import fakes from openstackclient.tests.unit import utils diff --git a/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py b/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py index 87643f128d..733fda6cb1 100644 --- a/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py +++ b/openstackclient/tests/unit/identity/v2_0/test_role_assignment.py @@ -12,8 +12,8 @@ # import copy -import mock +import mock from osc_lib import exceptions from openstackclient.identity.v2_0 import role_assignment diff --git a/openstackclient/tests/unit/identity/v3/fakes.py b/openstackclient/tests/unit/identity/v3/fakes.py index c7d298859f..997bcf63e8 100644 --- a/openstackclient/tests/unit/identity/v3/fakes.py +++ b/openstackclient/tests/unit/identity/v3/fakes.py @@ -14,11 +14,11 @@ # import copy -import mock import uuid from keystoneauth1 import access from keystoneauth1 import fixture +import mock from openstackclient.tests.unit import fakes from openstackclient.tests.unit import utils diff --git a/openstackclient/tests/unit/identity/v3/test_identity_provider.py b/openstackclient/tests/unit/identity/v3/test_identity_provider.py index def6e0ce54..dc82ab7422 100644 --- a/openstackclient/tests/unit/identity/v3/test_identity_provider.py +++ b/openstackclient/tests/unit/identity/v3/test_identity_provider.py @@ -13,6 +13,7 @@ # under the License. import copy + import mock from openstackclient.identity.v3 import identity_provider diff --git a/openstackclient/tests/unit/identity/v3/test_mappings.py b/openstackclient/tests/unit/identity/v3/test_mappings.py index 93fe1196c9..1d8e77d9e8 100644 --- a/openstackclient/tests/unit/identity/v3/test_mappings.py +++ b/openstackclient/tests/unit/identity/v3/test_mappings.py @@ -13,8 +13,8 @@ # under the License. import copy -import mock +import mock from osc_lib import exceptions from openstackclient.identity.v3 import mapping diff --git a/openstackclient/tests/unit/identity/v3/test_role.py b/openstackclient/tests/unit/identity/v3/test_role.py index 39dbd24466..281d530c7e 100644 --- a/openstackclient/tests/unit/identity/v3/test_role.py +++ b/openstackclient/tests/unit/identity/v3/test_role.py @@ -14,8 +14,8 @@ # import copy -import mock +import mock from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/identity/v3/test_role_assignment.py b/openstackclient/tests/unit/identity/v3/test_role_assignment.py index 32fbb7f1d4..835837e608 100644 --- a/openstackclient/tests/unit/identity/v3/test_role_assignment.py +++ b/openstackclient/tests/unit/identity/v3/test_role_assignment.py @@ -12,6 +12,7 @@ # import copy + import mock from openstackclient.identity.v3 import role_assignment diff --git a/openstackclient/tests/unit/identity/v3/test_trust.py b/openstackclient/tests/unit/identity/v3/test_trust.py index 614aab5470..1355b9089b 100644 --- a/openstackclient/tests/unit/identity/v3/test_trust.py +++ b/openstackclient/tests/unit/identity/v3/test_trust.py @@ -12,8 +12,8 @@ # import copy -import mock +import mock from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/identity/v3/test_user.py b/openstackclient/tests/unit/identity/v3/test_user.py index 96f5076655..920ee95051 100644 --- a/openstackclient/tests/unit/identity/v3/test_user.py +++ b/openstackclient/tests/unit/identity/v3/test_user.py @@ -14,8 +14,8 @@ # import contextlib -import mock +import mock from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/image/v1/fakes.py b/openstackclient/tests/unit/image/v1/fakes.py index 4b6d278c68..8030625743 100644 --- a/openstackclient/tests/unit/image/v1/fakes.py +++ b/openstackclient/tests/unit/image/v1/fakes.py @@ -14,9 +14,10 @@ # import copy -import mock import uuid +import mock + from openstackclient.tests.unit import fakes from openstackclient.tests.unit import utils from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes diff --git a/openstackclient/tests/unit/image/v1/test_image.py b/openstackclient/tests/unit/image/v1/test_image.py index 41ddc49fa5..8a83feb0c4 100644 --- a/openstackclient/tests/unit/image/v1/test_image.py +++ b/openstackclient/tests/unit/image/v1/test_image.py @@ -14,8 +14,8 @@ # import copy -import mock +import mock from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/image/v2/fakes.py b/openstackclient/tests/unit/image/v2/fakes.py index 0255ce38dc..eabc932573 100644 --- a/openstackclient/tests/unit/image/v2/fakes.py +++ b/openstackclient/tests/unit/image/v2/fakes.py @@ -14,11 +14,11 @@ # import copy -import mock import random import uuid from glanceclient.v2 import schemas +import mock from osc_lib import utils as common_utils import warlock diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index 484a2bc64b..429ddd282b 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -14,9 +14,9 @@ # import copy -import mock from glanceclient.v2 import schemas +import mock from osc_lib import exceptions from osc_lib import utils as common_utils import warlock diff --git a/openstackclient/tests/unit/integ/cli/test_shell.py b/openstackclient/tests/unit/integ/cli/test_shell.py index 4e91f6370e..78663fbcda 100644 --- a/openstackclient/tests/unit/integ/cli/test_shell.py +++ b/openstackclient/tests/unit/integ/cli/test_shell.py @@ -11,8 +11,8 @@ # under the License. import copy -import mock +import mock from osc_lib.tests import utils as osc_lib_utils from openstackclient import shell diff --git a/openstackclient/tests/unit/network/test_common.py b/openstackclient/tests/unit/network/test_common.py index 4b9a754b34..c8dce0af83 100644 --- a/openstackclient/tests/unit/network/test_common.py +++ b/openstackclient/tests/unit/network/test_common.py @@ -12,6 +12,7 @@ # import argparse + import mock import openstack diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index eadab58461..bdc1c1fb0e 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -13,11 +13,12 @@ import argparse import copy -import mock from random import choice from random import randint import uuid +import mock + from openstackclient.tests.unit import fakes from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes_v3 from openstackclient.tests.unit import utils diff --git a/openstackclient/tests/unit/network/v2/test_network.py b/openstackclient/tests/unit/network/v2/test_network.py index 7b20c79338..357088f345 100644 --- a/openstackclient/tests/unit/network/v2/test_network.py +++ b/openstackclient/tests/unit/network/v2/test_network.py @@ -11,10 +11,10 @@ # under the License. # -import mock -from mock import call import random +import mock +from mock import call from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index 97be5afd94..45e1045da0 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -12,8 +12,8 @@ # import argparse -import mock +import mock from mock import call from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/network/v2/test_subnet_pool.py b/openstackclient/tests/unit/network/v2/test_subnet_pool.py index 139fddf887..81f0278f26 100644 --- a/openstackclient/tests/unit/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/unit/network/v2/test_subnet_pool.py @@ -12,9 +12,9 @@ # import argparse + import mock from mock import call - from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/object/v1/test_container.py b/openstackclient/tests/unit/object/v1/test_container.py index 37b8c705b7..39e2d80f4a 100644 --- a/openstackclient/tests/unit/object/v1/test_container.py +++ b/openstackclient/tests/unit/object/v1/test_container.py @@ -14,6 +14,7 @@ # import copy + import mock from openstackclient.api import object_store_v1 as object_store diff --git a/openstackclient/tests/unit/object/v1/test_object.py b/openstackclient/tests/unit/object/v1/test_object.py index c0ac204dad..b629937351 100644 --- a/openstackclient/tests/unit/object/v1/test_object.py +++ b/openstackclient/tests/unit/object/v1/test_object.py @@ -14,6 +14,7 @@ # import copy + import mock from openstackclient.api import object_store_v1 as object_store diff --git a/openstackclient/tests/unit/test_shell.py b/openstackclient/tests/unit/test_shell.py index b9fac684c4..dff37f10b7 100644 --- a/openstackclient/tests/unit/test_shell.py +++ b/openstackclient/tests/unit/test_shell.py @@ -13,10 +13,10 @@ # under the License. # -import mock import os import sys +import mock from osc_lib.tests import utils as osc_lib_test_utils from oslo_utils import importutils import wrapt diff --git a/openstackclient/tests/unit/utils.py b/openstackclient/tests/unit/utils.py index 8f9cc7b17c..926dad87ea 100644 --- a/openstackclient/tests/unit/utils.py +++ b/openstackclient/tests/unit/utils.py @@ -14,8 +14,9 @@ # under the License. # -import fixtures import os + +import fixtures import testtools from openstackclient.tests.unit import fakes diff --git a/openstackclient/tests/unit/volume/v1/fakes.py b/openstackclient/tests/unit/volume/v1/fakes.py index fff5181dc4..de9c724f1e 100644 --- a/openstackclient/tests/unit/volume/v1/fakes.py +++ b/openstackclient/tests/unit/volume/v1/fakes.py @@ -14,10 +14,11 @@ # import copy -import mock import random import uuid +import mock + from openstackclient.tests.unit import fakes from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes from openstackclient.tests.unit import utils diff --git a/openstackclient/tests/unit/volume/v1/test_qos_specs.py b/openstackclient/tests/unit/volume/v1/test_qos_specs.py index a88c1cd83f..442840f922 100644 --- a/openstackclient/tests/unit/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/unit/volume/v1/test_qos_specs.py @@ -14,9 +14,9 @@ # import copy + import mock from mock import call - from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py index 6b79377352..eee5acd7ea 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume.py +++ b/openstackclient/tests/unit/volume/v1/test_volume.py @@ -14,9 +14,9 @@ # import argparse + import mock from mock import call - from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py index d321c71a27..27f37bd8c9 100644 --- a/openstackclient/tests/unit/volume/v2/fakes.py +++ b/openstackclient/tests/unit/volume/v2/fakes.py @@ -13,10 +13,10 @@ # import copy -import mock import random import uuid +import mock from osc_lib import utils as common_utils from openstackclient.tests.unit import fakes diff --git a/openstackclient/tests/unit/volume/v2/test_qos_specs.py b/openstackclient/tests/unit/volume/v2/test_qos_specs.py index 8f145a7e3f..2b935e205f 100644 --- a/openstackclient/tests/unit/volume/v2/test_qos_specs.py +++ b/openstackclient/tests/unit/volume/v2/test_qos_specs.py @@ -14,9 +14,9 @@ # import copy + import mock from mock import call - from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/volume/v2/test_snapshot.py b/openstackclient/tests/unit/volume/v2/test_snapshot.py index 16d0602b7c..e8f4ae5a4a 100644 --- a/openstackclient/tests/unit/volume/v2/test_snapshot.py +++ b/openstackclient/tests/unit/volume/v2/test_snapshot.py @@ -13,9 +13,9 @@ # import argparse + import mock from mock import call - from osc_lib import exceptions from osc_lib import utils diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py index 71e4eceac7..2fa924b8a5 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume.py +++ b/openstackclient/tests/unit/volume/v2/test_volume.py @@ -13,9 +13,9 @@ # import argparse + import mock from mock import call - from osc_lib import exceptions from osc_lib import utils diff --git a/test-requirements.txt b/test-requirements.txt index 5af8d0cf4f..84ada1d140 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,6 +5,7 @@ hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD +flake8-import-order==0.13 # LGPLv3 mock>=2.0 # BSD openstackdocstheme>=1.16.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 0f22650a9a..68b01b4537 100644 --- a/tox.ini +++ b/tox.ini @@ -91,3 +91,4 @@ exclude = .git,.tox,dist,doc,*lib/python*,*egg,build,tools # If 'ignore' is not set there are default errors and warnings that are set # Doc: http://flake8.readthedocs.org/en/latest/config.html#default ignore = __ +import-order-style = pep8