From bf810d24ed715910cf6b10e4fe995315a8c3bb5a Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Wed, 26 Jun 2019 16:30:35 -0400 Subject: [PATCH] Update flake8 style enforcement Added enforcement of H106, H203, H204 and H205 extensions to match neutron repo, fixing a few failures in the process. Also updated to support hacking 1.1.0, bringing in flake8 2.6.2 and pycodestyle 2.4.0 in the process. This ensures future python3 compatibility and a bit better code styling. Change-Id: Ibd9cff863eaff940755ccb9c20f39e29e2001cde --- lower-constraints.txt | 6 +++--- neutron_lib/tests/unit/db/test_api.py | 2 +- neutron_lib/tests/unit/hacking/test_checks.py | 4 ++-- neutron_lib/tests/unit/utils/test_runtime.py | 4 ++-- tox.ini | 6 +++++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 05cd734c7..7c1a6d4e0 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -13,12 +13,12 @@ eventlet==0.18.2 extras==1.0.0 fasteners==0.7.0 fixtures==3.0.0 -flake8==2.5.5 +flake8==2.6.2 flake8-import-order==0.12 future==0.16.0 futurist==1.2.0 greenlet==0.4.10 -hacking==0.12.0 +hacking==1.1.0 imagesize==0.7.1 iso8601==0.1.11 Jinja2==2.10 @@ -61,7 +61,7 @@ pep8==1.5.7 pika==0.10.0 pika-pool==0.1.3 prettytable==0.7.2 -pycodestyle==2.3.1 +pycodestyle==2.4.0 pyflakes==0.8.1 Pygments==2.2.0 pyinotify==0.9.6 diff --git a/neutron_lib/tests/unit/db/test_api.py b/neutron_lib/tests/unit/db/test_api.py index a6fe81114..d7454bf67 100644 --- a/neutron_lib/tests/unit/db/test_api.py +++ b/neutron_lib/tests/unit/db/test_api.py @@ -158,7 +158,7 @@ class TestDeadLockDecorator(_base.BaseTestCase): if exc_to_raise == db_exc.DBDeadlock: self.assertEqual(True, (fake_timer.counter <= sum(worst_case))) else: - self.assertTrue(sum(worst_case) >= fake_timer.counter) + self.assertGreaterEqual(sum(worst_case), fake_timer.counter) def test_all_deadlock_time_elapsed(self): self._test_retry_time_cost(db_exc.DBDeadlock) diff --git a/neutron_lib/tests/unit/hacking/test_checks.py b/neutron_lib/tests/unit/hacking/test_checks.py index 31fe36e16..6b23fcf09 100644 --- a/neutron_lib/tests/unit/hacking/test_checks.py +++ b/neutron_lib/tests/unit/hacking/test_checks.py @@ -38,13 +38,13 @@ class HackingTestCase(base.BaseTestCase): return check_fns def test_factory(self): - self.assertTrue(len(self._get_factory_checks(checks.factory)) > 0) + self.assertGreater(len(self._get_factory_checks(checks.factory)), 0) def test_neutron_lib_factory(self): lib_checks = self._get_factory_checks(checks._neutron_lib_factory) other_checks = self._get_factory_checks(checks.factory) - self.assertTrue(len(lib_checks) > 0) + self.assertGreater(len(lib_checks), 0) if other_checks: for other_check in other_checks: diff --git a/neutron_lib/tests/unit/utils/test_runtime.py b/neutron_lib/tests/unit/utils/test_runtime.py index 70df6906d..b22cd3b6f 100644 --- a/neutron_lib/tests/unit/utils/test_runtime.py +++ b/neutron_lib/tests/unit/utils/test_runtime.py @@ -116,5 +116,5 @@ class TestListPackageModules(base.BaseTestCase): def test_list_package_modules(self): # mainly just to ensure we can import modules for both PY2/PY3 - self.assertTrue( - len(runtime.list_package_modules('neutron_lib.exceptions')) > 3) + self.assertGreater( + len(runtime.list_package_modules('neutron_lib.exceptions')), 3) diff --git a/tox.ini b/tox.ini index 24ef4158f..58a5ee78f 100644 --- a/tox.ini +++ b/tox.ini @@ -91,8 +91,12 @@ commands = {toxinidir}/tools/api_report.sh [flake8] +# H106: Don't put vim configuration in source files +# H203: Use assertIs(Not)None to check for None +# H204: Use assert(Not)Equal to check for equality +# H205: Use assert(Greater|Less)(Equal) for comparison # H904: Delay string interpolations at logging calls -enable-extensions=H904 +enable-extensions=H106,H203,H204,H205,H904 show-source = True exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools import-order-style = pep8