Merge "Test: Stop using non-existent method of Mock"
This commit is contained in:
commit
35634e9f4c
@ -80,6 +80,9 @@ def skip_ignored_lines(func):
|
||||
def _parse_assert_mock_str(line):
|
||||
point = line.find(".assert_")
|
||||
|
||||
if point == -1:
|
||||
point = line.find(".called_once_with(")
|
||||
|
||||
if point != -1:
|
||||
end_pos = line[point:].find("(") + point
|
||||
return point, line[point + 1: end_pos], line[: point]
|
||||
@ -94,10 +97,12 @@ def check_assert_methods_from_mock(logical_line, physical_line, filename):
|
||||
N301 - base error number
|
||||
N302 - related to nonexistent "assert_called"
|
||||
N303 - related to nonexistent "assert_called_once"
|
||||
N304 - related to nonexistent "called_once_with"
|
||||
"""
|
||||
|
||||
correct_names = ["assert_any_call", "assert_called_once_with",
|
||||
"assert_called_with", "assert_has_calls"]
|
||||
"assert_called_with", "assert_has_calls",
|
||||
"assert_not_called"]
|
||||
ignored_files = ["./tests/unit/test_hacking.py"]
|
||||
|
||||
if filename.startswith("./tests") and filename not in ignored_files:
|
||||
@ -123,6 +128,11 @@ def check_assert_methods_from_mock(logical_line, physical_line, filename):
|
||||
"'assertEqual(1, %s.call_count)' "
|
||||
"or '%s.assert_called_once_with()'"
|
||||
" instead." % (obj_name, obj_name))
|
||||
elif method_name == "called_once_with":
|
||||
error_number = "N304"
|
||||
custom_msg = ("Maybe, you should try to use "
|
||||
"'%s.assert_called_once_with()'"
|
||||
" instead." % obj_name)
|
||||
else:
|
||||
custom_msg = ("Correct 'assert_*' methods: '%s'."
|
||||
% "', '".join(correct_names))
|
||||
|
@ -85,9 +85,9 @@ class LbaasTestCase(test.TestCase):
|
||||
fake_args = {"lbaas_version": 1}
|
||||
lb_context = lbaas_context.Lbaas(self.get_context(**fake_args))
|
||||
lb_context.setup()
|
||||
mock_utils.iterate_per_tenants.called_once_with(
|
||||
mock_utils.iterate_per_tenants.assert_called_once_with(
|
||||
lb_context.context["users"])
|
||||
net_wrapper.supports_extension.called_once_with("lbaas")
|
||||
net_wrapper.supports_extension.assert_called_once_with("lbaas")
|
||||
for tenant_id, tenant_ctx in (
|
||||
sorted(lb_context.context["tenants"].items())):
|
||||
for network in tenant_ctx["networks"]:
|
||||
@ -107,8 +107,7 @@ class LbaasTestCase(test.TestCase):
|
||||
net_wrapper = mock_wrap(mock_clients.return_value)
|
||||
net_wrapper.supports_extension.return_value = (False, None)
|
||||
lb_context.setup()
|
||||
mock_utils.iterate_per_tenants.called_once_with(
|
||||
lb_context.context["users"])
|
||||
mock_utils.iterate_per_tenants.assert_not_called()
|
||||
net_wrapper.supports_extension.assert_called_once_with("lbaas")
|
||||
assert not net_wrapper.create_v1_pool.called
|
||||
|
||||
|
@ -398,7 +398,7 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
service = self.get_wrapper()
|
||||
pool = {"pool": {"id": "pool-id"}}
|
||||
service.delete_v1_pool(pool["pool"]["id"])
|
||||
service.client.delete_pool.called_once_with([mock.call("pool-id")])
|
||||
service.client.delete_pool.assert_called_once_with("pool-id")
|
||||
|
||||
@mock.patch("rally.plugins.openstack.wrappers.network.NeutronWrapper"
|
||||
".supports_extension", return_value=(True, ""))
|
||||
|
Loading…
x
Reference in New Issue
Block a user