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 <takanattie@gmail.com>
Change-Id: I86202f36f1b7c0bce8b29558ad1e377c336b7258
This commit is contained in:
Takashi Natsume 2021-05-21 19:05:35 +09:00 committed by Rodolfo Alonso
parent 7e98d18927
commit 05ee23ea15
5 changed files with 8 additions and 6 deletions

View File

@ -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 - [N322] Detect common errors with assert_called_once_with
- [N328] Detect wrong usage with assertEqual - [N328] Detect wrong usage with assertEqual
- [N329] Use assertCountEqual() instead of assertItemsEqual()
- [N330] Use assertEqual(*empty*, observed) instead of - [N330] Use assertEqual(*empty*, observed) instead of
assertEqual(observed, *empty*) assertEqual(observed, *empty*)
- [N331] Detect wrong usage with assertTrue(isinstance()). - [N331] Detect wrong usage with assertTrue(isinstance()).

View File

@ -91,9 +91,9 @@ def check_asserttruefalse(logical_line, filename):
@core.flake8ext @core.flake8ext
def check_assertitemsequal(logical_line, filename): def check_assertitemsequal(logical_line, filename):
"""N328 - Don't use assertItemsEqual.""" """N329 - Don't use assertItemsEqual."""
if 'neutron/tests/' in filename: 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 " msg = ("N329: Use assertCountEqual() instead of "
"assertItemsEqual()") "assertItemsEqual()")
yield (0, msg) yield (0, msg)

View File

@ -244,7 +244,7 @@ class TestNbApi(BaseOvnIdlTest):
exp_values = [(lb['name'], lb['external_ids']) exp_values = [(lb['name'], lb['external_ids'])
for lb in self.data['lbs']] for lb in self.data['lbs']]
lbs_values = [(lb.name, lb.external_ids) for lb in 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): def test_get_router_floatingip_lbs(self):
f = self.nbapi.get_router_floatingip_lbs f = self.nbapi.get_router_floatingip_lbs
@ -260,7 +260,7 @@ class TestNbApi(BaseOvnIdlTest):
lbs_values = [(lb.name, lb.external_ids) lbs_values = [(lb.name, lb.external_ids)
for lb in f(exp_router_name)] for lb in f(exp_router_name)]
self.assertTrue(exp_values) 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): def test_get_floatingip_in_nat_or_lb(self):
f = self.nbapi.get_floatingip_in_nat_or_lb f = self.nbapi.get_floatingip_in_nat_or_lb

View File

@ -1429,9 +1429,9 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
nb_pfs.append(pf) nb_pfs.append(pf)
if should_match: if should_match:
self.assertItemsEqual(nb_pfs, db_pfs) self.assertCountEqual(nb_pfs, db_pfs)
else: else:
self.assertRaises(AssertionError, self.assertItemsEqual, self.assertRaises(AssertionError, self.assertCountEqual,
nb_pfs, db_pfs) nb_pfs, db_pfs)
def _validate_port_groups(self, should_match=True): def _validate_port_groups(self, should_match=True):

View File

@ -185,6 +185,7 @@ extension =
# Checks specific to neutron repo # Checks specific to neutron repo
N322 = neutron.hacking.checks:check_assert_called_once_with N322 = neutron.hacking.checks:check_assert_called_once_with
N328 = neutron.hacking.checks:check_asserttruefalse N328 = neutron.hacking.checks:check_asserttruefalse
N329 = neutron.hacking.checks:check_assertitemsequal
N330 = neutron.hacking.checks:check_assertempty N330 = neutron.hacking.checks:check_assertempty
N331 = neutron.hacking.checks:check_assertisinstance N331 = neutron.hacking.checks:check_assertisinstance
N332 = neutron.hacking.checks:check_assertequal_for_httpcode N332 = neutron.hacking.checks:check_assertequal_for_httpcode