From c69701eb73fa478dc96449230353dfa6172e9d5d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 17 Jan 2024 01:53:43 +0900 Subject: [PATCH] Bump hacking hacking 3.0.x is really old. Let's bump it to the latest version available. This also fixes some errors detected but some rules are excluded now. See the comments in tox.ini for further details. Change-Id: I2565e5f5e791dfdd9bbc1890b35c413965d83626 --- neutron_lib/api/definitions/bgpvpn_routes_control.py | 2 +- neutron_lib/hacking/checks.py | 2 +- neutron_lib/tests/unit/api/validators/test_validators.py | 4 ++-- neutron_lib/tests/unit/callbacks/test_events.py | 2 +- neutron_lib/tests/unit/hacking/test_checks.py | 2 +- neutron_lib/tests/unit/placement/test_client.py | 2 +- requirements.txt | 3 --- test-requirements.txt | 4 ++-- tox.ini | 5 +++++ 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/neutron_lib/api/definitions/bgpvpn_routes_control.py b/neutron_lib/api/definitions/bgpvpn_routes_control.py index 39f51c017..06a758aba 100644 --- a/neutron_lib/api/definitions/bgpvpn_routes_control.py +++ b/neutron_lib/api/definitions/bgpvpn_routes_control.py @@ -53,7 +53,7 @@ RESOURCE_NAME = bgpvpn.RESOURCE_NAME COLLECTION_NAME = bgpvpn.COLLECTION_NAME LOCAL_PREF_KEY = 'local_pref' -LOCAL_PREF_RANGE = [0, 2**32-1] # RFC 4271, section 4.3 (p.18) +LOCAL_PREF_RANGE = [0, 2**32 - 1] # RFC 4271, section 4.3 (p.18) RESOURCE_ATTRIBUTE_MAP = { COLLECTION_NAME: { diff --git a/neutron_lib/hacking/checks.py b/neutron_lib/hacking/checks.py index a15235254..380a4f028 100644 --- a/neutron_lib/hacking/checks.py +++ b/neutron_lib/hacking/checks.py @@ -124,7 +124,7 @@ def check_no_contextlib_nested(logical_line, filename): "more information.") if contextlib_nested.match(logical_line): - yield(0, msg) + yield (0, msg) @core.flake8ext diff --git a/neutron_lib/tests/unit/api/validators/test_validators.py b/neutron_lib/tests/unit/api/validators/test_validators.py index ca480a1ac..c45605d30 100644 --- a/neutron_lib/tests/unit/api/validators/test_validators.py +++ b/neutron_lib/tests/unit/api/validators/test_validators.py @@ -960,12 +960,12 @@ class TestAttributeValidation(base.BaseTestCase): items = [['a', 'b'], ['c', 'd'], ['a', 'b']] msg = validators._validate_list_of_items(mock.Mock(), items) - error = "Duplicate items in the list: '%s'" % ['a', 'b'] + error = "Duplicate items in the list: '%s'" % str(['a', 'b']) self.assertEqual(error, msg) items = [{'a': 'b'}, {'c': 'd'}, {'a': 'b'}] msg = validators._validate_list_of_items(mock.Mock(), items) - error = "Duplicate items in the list: '%s'" % {'a': 'b'} + error = "Duplicate items in the list: '%s'" % str({'a': 'b'}) self.assertEqual(error, msg) def test_validate_dict_type(self): diff --git a/neutron_lib/tests/unit/callbacks/test_events.py b/neutron_lib/tests/unit/callbacks/test_events.py index f3be8ac45..575077365 100644 --- a/neutron_lib/tests/unit/callbacks/test_events.py +++ b/neutron_lib/tests/unit/callbacks/test_events.py @@ -28,7 +28,7 @@ class EventPayloadTestCase(base.BaseTestCase): self.assertEqual(meta, e.metadata) event_meta = e.metadata event_meta['k3'] = 'v3' - self.assertTrue('k3' in e.metadata) + self.assertIn('k3', e.metadata) def test_request_body(self): e = events.EventPayload(mock.ANY, request_body={'k', 'v'}) diff --git a/neutron_lib/tests/unit/hacking/test_checks.py b/neutron_lib/tests/unit/hacking/test_checks.py index 4433edeea..bfe511fe4 100644 --- a/neutron_lib/tests/unit/hacking/test_checks.py +++ b/neutron_lib/tests/unit/hacking/test_checks.py @@ -31,7 +31,7 @@ class HackingTestCase(base.BaseTestCase): def _reg(check_fn): self.assertTrue(hasattr(check_fn, '__call__')) - self.assertFalse(check_fn in check_fns) + self.assertNotIn(check_fn, check_fns) check_fns.append(check_fn) factory(_reg) diff --git a/neutron_lib/tests/unit/placement/test_client.py b/neutron_lib/tests/unit/placement/test_client.py index 52a5ebfa9..873849eeb 100644 --- a/neutron_lib/tests/unit/placement/test_client.py +++ b/neutron_lib/tests/unit/placement/test_client.py @@ -810,7 +810,7 @@ class TestPlacementAPIClient(base.BaseTestCase): def test_update_qos_allocation_other_conflict(self): mock_rsp_get = self._get_allocation_response( {RESOURCE_PROVIDER_UUID: {'c': 3}}) - self.placement_fixture.mock_get.side_effect = 10*[mock_rsp_get] + self.placement_fixture.mock_get.side_effect = 10 * [mock_rsp_get] mock_rsp_put = mock.Mock() mock_rsp_put.text = '' mock_rsp_put.json = lambda: { diff --git a/requirements.txt b/requirements.txt index f318e9c15..a489478f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,3 @@ -# Requirements lower bounds listed here are our best effort to keep them up to -# date but we do not test them so no guarantee of having them all correct. If -# you find any incorrect lower bounds, let us know or propose a fix. pbr>=4.0.0 # Apache-2.0 SQLAlchemy>=1.2.0 # MIT diff --git a/test-requirements.txt b/test-requirements.txt index 20e64d4da..9aacc1fad 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,10 +1,10 @@ -hacking>=3.0.1,<3.1.0 # Apache-2.0 +hacking>=6.1.0,<6.2.0 # Apache-2.0 bandit!=1.6.0,>=1.1.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT fixtures>=3.0.0 # Apache-2.0/BSD -flake8-import-order==0.12 # LGPLv3 +flake8-import-order>=0.18.0,<0.19.0 # LGPLv3 pylint>=2.2.0 # GPLv2 isort==4.3.21 # MIT python-subunit>=1.0.0 # Apache-2.0/BSD diff --git a/tox.ini b/tox.ini index ca22cc78f..3f6bc8556 100644 --- a/tox.ini +++ b/tox.ini @@ -95,6 +95,11 @@ commands = oslo_debug_helper -t neutron_lib/tests/unit {posargs} # H205: Use assert(Greater|Less)(Equal) for comparison # H904: Delay string interpolations at logging calls enable-extensions = H106,H203,H204,H205,H904 +# Most of the whitespace related rules (E12* and E131) are excluded. +# W504 skipped because it conflicts with W503 +# I202 skipped because it does not allow newline between 3rd party libraries +# import and neutron-lib code import, which is wrong +ignore = E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,W504,I202 show-source = True exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools import-order-style = pep8