Merge "Replace assertRaisesRegexp with assertRaisesRegex"

This commit is contained in:
Zuul 2020-08-29 08:42:35 +00:00 committed by Gerrit Code Review
commit 97da0fe7ec
3 changed files with 17 additions and 2 deletions

View File

@ -50,6 +50,8 @@ log_translation = re.compile(
r"\(")
yield_not_followed_by_space = re.compile(r"^\s*yield(?:\(|{|\[|\"|').*$")
assert_raises_regexp = re.compile(r"assertRaisesRegexp\(")
@core.flake8ext
def check_explicit_underscore_import(logical_line, filename):
@ -100,3 +102,15 @@ def yield_followed_by_space(logical_line):
if yield_not_followed_by_space.match(logical_line):
yield (0,
"M303: Yield keyword should be followed by a space.")
@core.flake8ext
def assert_raisesRegexp(logical_line):
"""Check that assertRaisesRegexp is not used.
M304
"""
res = assert_raises_regexp.search(logical_line)
if res:
yield (0, "M304: assertRaisesRegex must be used instead "
"of assertRaisesRegexp")

View File

@ -680,7 +680,7 @@ class TestHandleHost(testtools.TestCase):
obj = handle_host.HandleHost()
self.assertRaisesRegexp(
self.assertRaisesRegex(
Exception, "Failed to get nodes tag from crm_mon xml.",
obj._check_host_status_by_crm_mon)
mock_get_crmmon_xml.assert_called_once_with()
@ -777,7 +777,7 @@ class TestHandleHost(testtools.TestCase):
obj = handle_host.HandleHost()
self.assertRaisesRegexp(
self.assertRaisesRegex(
Exception, "Failed to get node_state tag from cib xml.",
obj._check_host_status_by_cibadmin)
mock_get_cib_xml.assert_called_once_with()

View File

@ -90,6 +90,7 @@ extension =
M301 = checks:check_explicit_underscore_import
M302 = checks:no_translate_logs
M303 = checks:yield_followed_by_space
M304 = checks:assert_raisesRegexp
paths = ./masakarimonitors/hacking
[testenv:lower-constraints]