Browse Source

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
changes/70/792570/3
Takashi Natsume 4 months ago
committed by Rodolfo Alonso
parent
commit
05ee23ea15
  1. 1
      HACKING.rst
  2. 4
      neutron/hacking/checks.py
  3. 4
      neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py
  4. 4
      neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py
  5. 1
      tox.ini

1
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()).

4
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)

4
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

4
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):

1
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

Loading…
Cancel
Save