Browse Source

Merge "Switch from unittest2 compat methods to Python 3.x methods"

changes/87/779287/1
Zuul 7 months ago
committed by Gerrit Code Review
parent
commit
5fdeba0b48
  1. 1
      HACKING.rst
  2. 12
      ovn_octavia_provider/hacking/checks.py
  3. 9
      ovn_octavia_provider/tests/functional/base.py
  4. 1
      tox.ini

1
HACKING.rst

@ -16,3 +16,4 @@ Below you can find a list of checks specific to this repository.
- [N344] Python 3: Do not use filter(lambda obj: test(obj), data). Replace it
with [obj for obj in data if test(obj)].
- [N347] Test code must not import mock library
- [N348] Detect usage of assertItemsEqual

12
ovn_octavia_provider/hacking/checks.py

@ -181,3 +181,15 @@ def check_no_import_mock(logical_line, filename, noqa):
for regex in import_mock, import_from_mock:
if re.match(regex, logical_line):
yield(0, msg)
@core.flake8ext
def check_assertcountequal(logical_line, filename):
"""N348 - Enforce using assertCountEqual."""
msg = ("N348: Use assertCountEqual(expected, observed) "
"instead of assertItemsEqual(observed, expected)")
if 'ovn_octavia_provider/tests/' in filename:
if re.search(r"assertItemsEqual\([^,]*,\s*(,[^,]*)?", logical_line):
yield (0, msg)

9
ovn_octavia_provider/tests/functional/base.py

@ -192,11 +192,10 @@ class TestOvnOctaviaBase(base.TestOVNFunctionalBase,
def _validate_loadbalancers(self, expected_lbs):
observed_lbs = self._get_loadbalancers()
# NOTE (mjozefcz): assertItemsEqual works only on first level
# of comparison, if dicts inside dics are in diffrent
# NOTE (mjozefcz): assertCountEqual works only on first level
# of comparison, if dicts inside dicts are in different
# order it would fail.
self.assertEqual(len(expected_lbs),
len(observed_lbs))
self.assertEqual(len(expected_lbs), len(observed_lbs))
for expected_lb in expected_lbs:
# search for LB with same name and protocol
found = False
@ -308,7 +307,7 @@ class TestOvnOctaviaBase(base.TestOVNFunctionalBase,
calls_found.append(expected_status)
break
# Validate if we found all expected calls.
self.assertItemsEqual(expected_statuses, calls_found)
self.assertCountEqual(expected_statuses, calls_found)
def _wait_for_status_and_validate(self, lb_data, expected_status,
check_call=True):

1
tox.ini

@ -118,6 +118,7 @@ extension =
N343 = checks:check_no_imports_from_tests
N344 = checks:check_python3_no_filter
N347 = checks:check_no_import_mock
N348 = checks:check_assertcountequal
paths =./ovn_octavia_provider/hacking
[testenv:genconfig]

Loading…
Cancel
Save