diff --git a/tests/hacking/README.rst b/tests/hacking/README.rst index c3bc311d..a5cf1ecc 100644 --- a/tests/hacking/README.rst +++ b/tests/hacking/README.rst @@ -15,6 +15,7 @@ Rally Specific Commandments * [N310] - Ensure that ``rally.common.log`` is used as logging module * [N311] - Validate that debug level logs are not translated * [N312] - Validate correctness of debug on check. + * [N313] - Validate that LOG.warning is used instead of deprecated LOG.warn. * [N32x] - Reserved for rules related to assert* methods * [N320] - Ensure that ``assertTrue(isinstance(A, B))`` is not used * [N321] - Ensure that ``assertEqual(type(A), B)`` is not used diff --git a/tests/hacking/checks.py b/tests/hacking/checks.py index 7e20e3e2..e454768d 100644 --- a/tests/hacking/checks.py +++ b/tests/hacking/checks.py @@ -68,6 +68,7 @@ re_db_import = re.compile(r"^from rally.common import db") re_objects_import = re.compile(r"^from rally.common import objects") re_old_type_class = re.compile(r"^\s*class \w+(\(\))?:") re_datetime_alias = re.compile(r"^(from|import) datetime(?!\s+as\s+dt$)") +re_log_warn = re.compile(r"(.)*LOG\.(warn)\(\s*('|\"|_)") def skip_ignored_lines(func): @@ -555,6 +556,12 @@ def check_objects_imports_in_cli(logical_line, physical_line, filename): "`rally.common.objects``.") +@skip_ignored_lines +def check_log_warn(logical_line, physical_line, filename): + if re_log_warn.search(logical_line): + yield(0, "N313 LOG.warn is deprecated, please use LOG.warning") + + def factory(register): register(check_assert_methods_from_mock) register(check_import_of_logging) @@ -577,3 +584,4 @@ def factory(register): register(check_objects_imports_in_cli) register(check_old_type_class) register(check_no_six_iteritems) + register(check_log_warn) diff --git a/tests/unit/test_hacking.py b/tests/unit/test_hacking.py index a22fbd49..42e0fb0c 100644 --- a/tests/unit/test_hacking.py +++ b/tests/unit/test_hacking.py @@ -401,3 +401,9 @@ class HackingTestCase(test.TestCase): line = "import datetime as dt" checkres = checks.check_datetime_alias(line, line, "fakefile") + + def test_check_log_warn(self): + bad_samples = ["LOG.warn('foo')", "LOG.warn(_('bar'))"] + self._assert_bad_samples(checks.check_log_warn, bad_samples) + good_samples = ["LOG.warning('foo')", "LOG.warning(_('bar'))"] + self._assert_good_samples(checks.check_log_warn, good_samples)