Replace deprecated assertRaisesRegexp
It was deprecated in favor of assertRaisesRegex added in Python 3.2. We can replace it now because Python 2 is no longer supported. Change-Id: I4cec6e44d48bcee9808bfd647f3a45cd8b1e2f11
This commit is contained in:
parent
e47e0289fb
commit
788970e28f
@ -23,6 +23,7 @@ Cloudkitty Specific Commandments
|
||||
- [C320] Do not use LOG.warn as it's deprecated.
|
||||
- [C321] Ensure that the _() function is explicitly imported to ensure
|
||||
proper translations.
|
||||
- [C322] Check for usage of deprecated assertRaisesRegexp
|
||||
|
||||
LOG Translations
|
||||
----------------
|
||||
|
@ -52,6 +52,7 @@ assert_no_xrange_re = re.compile(r"\s*xrange\s*\(")
|
||||
assert_True = re.compile(r".*assertEqual\(True, .*\)")
|
||||
assert_None = re.compile(r".*assertEqual\(None, .*\)")
|
||||
no_log_warn = re.compile(r".*LOG.warn\(.*\)")
|
||||
asse_raises_regexp = re.compile(r"assertRaisesRegexp\(")
|
||||
|
||||
|
||||
class BaseASTChecker(ast.NodeVisitor):
|
||||
@ -352,3 +353,15 @@ def no_log_warn_check(logical_line):
|
||||
msg = ("C320: LOG.warn is deprecated, please use LOG.warning!")
|
||||
if re.match(no_log_warn, logical_line):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def assert_raises_regexp(logical_line):
|
||||
"""Check for usage of deprecated assertRaisesRegexp
|
||||
|
||||
C322
|
||||
"""
|
||||
res = asse_raises_regexp.search(logical_line)
|
||||
if res:
|
||||
yield (0, "C322: assertRaisesRegex must be used instead "
|
||||
"of assertRaisesRegexp")
|
||||
|
@ -48,9 +48,9 @@ class TestReprocessSchedulerPostApi(tests.TestCase):
|
||||
"a reprocessing."
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_scope_ids,
|
||||
self.scope_ids)
|
||||
self.assertRaisesRegex(http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_scope_ids,
|
||||
self.scope_ids)
|
||||
|
||||
self.scope_ids.remove('ALL')
|
||||
self.endpoint.validate_scope_ids(self.scope_ids)
|
||||
@ -63,12 +63,12 @@ class TestReprocessSchedulerPostApi(tests.TestCase):
|
||||
"a previously processed timestamp."
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_inputs,
|
||||
self.end_reprocess_time, "", self.scope_ids,
|
||||
self.start_reprocess_time)
|
||||
self.assertRaisesRegex(http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_inputs,
|
||||
self.end_reprocess_time, "", self.scope_ids,
|
||||
self.start_reprocess_time)
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_inputs, self.end_reprocess_time,
|
||||
" ", self.scope_ids, self.start_reprocess_time)
|
||||
@ -90,10 +90,10 @@ class TestReprocessSchedulerPostApi(tests.TestCase):
|
||||
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_inputs,
|
||||
self.end_reprocess_time, self.reason,
|
||||
self.scope_ids, self.start_reprocess_time)
|
||||
self.assertRaisesRegex(http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_inputs,
|
||||
self.end_reprocess_time, self.reason,
|
||||
self.scope_ids, self.start_reprocess_time)
|
||||
|
||||
self.end_reprocess_time = original_end_reprocess_time
|
||||
self.endpoint.validate_inputs(
|
||||
@ -113,7 +113,7 @@ class TestReprocessSchedulerPostApi(tests.TestCase):
|
||||
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.check_if_there_are_invalid_scopes, all_scopes,
|
||||
self.end_reprocess_time, self.scope_ids, self.start_reprocess_time)
|
||||
@ -206,7 +206,7 @@ class TestReprocessSchedulerPostApi(tests.TestCase):
|
||||
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_reprocessing_schedules_overlaps,
|
||||
self.generate_all_scopes_object(),
|
||||
@ -244,7 +244,7 @@ class TestReprocessSchedulerPostApi(tests.TestCase):
|
||||
self.start_reprocess_time)
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_start_end_for_reprocessing, all_scopes,
|
||||
self.end_reprocess_time, start_reprocess_time)
|
||||
@ -261,7 +261,7 @@ class TestReprocessSchedulerPostApi(tests.TestCase):
|
||||
self.end_reprocess_time)
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
http_exceptions.BadRequest, expected_message,
|
||||
self.endpoint.validate_start_end_for_reprocessing, all_scopes,
|
||||
end_processing_time, self.start_reprocess_time)
|
||||
|
@ -305,3 +305,13 @@ class HackingTestCase(tests.TestCase):
|
||||
"hacking check.')"))))
|
||||
self.assertEqual(1, len(list(checks.no_log_warn_check(
|
||||
"LOG.warn('We should not use LOG.wan')"))))
|
||||
|
||||
def test_oslo_assert_raises_regexp(self):
|
||||
code = """
|
||||
self.assertRaisesRegexp(ValueError,
|
||||
"invalid literal for.*XYZ'$",
|
||||
int,
|
||||
'XYZ')
|
||||
"""
|
||||
self._assert_has_errors(code, checks.assert_raises_regexp,
|
||||
expected_errors=[(1, 0, "C322")])
|
||||
|
@ -544,7 +544,7 @@ class WorkerTest(tests.TestCase):
|
||||
"resource 'metric1'"
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(
|
||||
self.assertRaisesRegex(
|
||||
collector.NoDataCollected, expected_message, self.worker._collect,
|
||||
metric, timestamp_now)
|
||||
|
||||
@ -921,8 +921,8 @@ class ReprocessingWorkerTest(tests.TestCase):
|
||||
"does not seem to exist anymore."
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(Exception, expected_message,
|
||||
self.reprocessing_worker.load_scope_key)
|
||||
self.assertRaisesRegex(Exception, expected_message,
|
||||
self.reprocessing_worker.load_scope_key)
|
||||
|
||||
self.state_manager_get_all_mock.assert_has_calls([
|
||||
mock.call(self.reprocessing_worker._tenant_id)])
|
||||
@ -935,8 +935,8 @@ class ReprocessingWorkerTest(tests.TestCase):
|
||||
"found for scope [toStringMock]."
|
||||
expected_message = re.escape(expected_message)
|
||||
|
||||
self.assertRaisesRegexp(Exception, expected_message,
|
||||
self.reprocessing_worker.load_scope_key)
|
||||
self.assertRaisesRegex(Exception, expected_message,
|
||||
self.reprocessing_worker.load_scope_key)
|
||||
|
||||
self.state_manager_get_all_mock.assert_has_calls([
|
||||
mock.call(self.reprocessing_worker._tenant_id)])
|
||||
|
Loading…
x
Reference in New Issue
Block a user