Replace assertRaisesRegexp with assertRaisesRegex

This replaces the deprecated (in python 3.2) unittest.TestCase method
assertRaisesRegexp() with assertRaisesRegex().

Also add associated hacking check.

Change-Id: I62d5b4c0259c6e2e0fee361542d4b1234ab0ea57
Signed-off-by: Chuck Short <chucks@redhat.com>
This commit is contained in:
Chuck Short 2018-08-27 10:15:19 -04:00 committed by tpatil
parent be1173e853
commit 886543d9e7
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]