From 05ee23ea15d12259c14be0c43a07bf46ccff6f0b Mon Sep 17 00:00:00 2001 From: Takashi Natsume Date: Fri, 21 May 2021 19:05:35 +0900 Subject: [PATCH] Follow up for replacing assertItemsEqual The assertItemsEqual has been replaced with assertCountEqual since I7c20fec08e5dc9f67b34100c925ea6724bbd25f0 . However the hacking check has not been enabled. This patch enables the hacking check and replace remaining assertItemsEqual with assertCountEqual. Signed-off-by: Takashi Natsume Change-Id: I86202f36f1b7c0bce8b29558ad1e377c336b7258 --- HACKING.rst | 1 + neutron/hacking/checks.py | 4 ++-- .../ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py | 4 ++-- .../ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py | 4 ++-- tox.ini | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 31da34521df..18b63422c11 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -16,6 +16,7 @@ Below you can find a list of checks specific to this repository. - [N322] Detect common errors with assert_called_once_with - [N328] Detect wrong usage with assertEqual +- [N329] Use assertCountEqual() instead of assertItemsEqual() - [N330] Use assertEqual(*empty*, observed) instead of assertEqual(observed, *empty*) - [N331] Detect wrong usage with assertTrue(isinstance()). diff --git a/neutron/hacking/checks.py b/neutron/hacking/checks.py index 6a8ee69b04d..8043b53890d 100644 --- a/neutron/hacking/checks.py +++ b/neutron/hacking/checks.py @@ -91,9 +91,9 @@ def check_asserttruefalse(logical_line, filename): @core.flake8ext def check_assertitemsequal(logical_line, filename): - """N328 - Don't use assertItemsEqual.""" + """N329 - Don't use assertItemsEqual.""" if 'neutron/tests/' in filename: - if re.search(r"assertItemsEqual\(", logical_line): + if re.search(r"assertItemsEqual[\(,]", logical_line): msg = ("N329: Use assertCountEqual() instead of " "assertItemsEqual()") yield (0, msg) diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py index 3bd6ef4aa3b..e3fb7ad0b6e 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py @@ -244,7 +244,7 @@ class TestNbApi(BaseOvnIdlTest): exp_values = [(lb['name'], lb['external_ids']) for lb in self.data['lbs']] lbs_values = [(lb.name, lb.external_ids) for lb in lbs] - self.assertItemsEqual(exp_values, lbs_values) + self.assertCountEqual(exp_values, lbs_values) def test_get_router_floatingip_lbs(self): f = self.nbapi.get_router_floatingip_lbs @@ -260,7 +260,7 @@ class TestNbApi(BaseOvnIdlTest): lbs_values = [(lb.name, lb.external_ids) for lb in f(exp_router_name)] self.assertTrue(exp_values) - self.assertItemsEqual(exp_values, lbs_values) + self.assertCountEqual(exp_values, lbs_values) def test_get_floatingip_in_nat_or_lb(self): f = self.nbapi.get_floatingip_in_nat_or_lb diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py index 0687661eefb..216f29fc93a 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py @@ -1429,9 +1429,9 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): nb_pfs.append(pf) if should_match: - self.assertItemsEqual(nb_pfs, db_pfs) + self.assertCountEqual(nb_pfs, db_pfs) else: - self.assertRaises(AssertionError, self.assertItemsEqual, + self.assertRaises(AssertionError, self.assertCountEqual, nb_pfs, db_pfs) def _validate_port_groups(self, should_match=True): diff --git a/tox.ini b/tox.ini index dfff3509e7d..e5baebc6863 100644 --- a/tox.ini +++ b/tox.ini @@ -185,6 +185,7 @@ extension = # Checks specific to neutron repo N322 = neutron.hacking.checks:check_assert_called_once_with N328 = neutron.hacking.checks:check_asserttruefalse + N329 = neutron.hacking.checks:check_assertitemsequal N330 = neutron.hacking.checks:check_assertempty N331 = neutron.hacking.checks:check_assertisinstance N332 = neutron.hacking.checks:check_assertequal_for_httpcode