Merge "hacking: disable log translations check"
This commit is contained in:
commit
9f758db4c7
@ -17,8 +17,6 @@ import re
|
||||
|
||||
from hacking import core
|
||||
from neutron_lib.hacking import checks
|
||||
import pep8
|
||||
import six
|
||||
|
||||
|
||||
def flake8ext(f):
|
||||
@ -63,10 +61,6 @@ def _regex_for_level(level, hint):
|
||||
}
|
||||
|
||||
|
||||
log_translation_hint = re.compile(
|
||||
'|'.join('(?:%s)' % _regex_for_level(level, hint)
|
||||
for level, hint in six.iteritems(_all_log_levels)))
|
||||
|
||||
log_warn = re.compile(
|
||||
r"(.)*LOG\.(warn)\(\s*('|\"|_)")
|
||||
unittest_imports_dot = re.compile(r"\bimport[\s]+unittest\b")
|
||||
@ -78,20 +72,6 @@ tests_imports_from1 = re.compile(r"\bfrom[\s]+neutron.tests\b")
|
||||
tests_imports_from2 = re.compile(r"\bfrom[\s]+neutron[\s]+import[\s]+tests\b")
|
||||
|
||||
|
||||
@flake8ext
|
||||
def validate_log_translations(logical_line, physical_line, filename):
|
||||
"""N320 - Log messages require translation."""
|
||||
# Translations are not required in the test directory
|
||||
if "neutron/tests" in filename:
|
||||
return
|
||||
if pep8.noqa(physical_line):
|
||||
return
|
||||
|
||||
msg = "N320: Log messages require translation hints!"
|
||||
if log_translation_hint.match(logical_line):
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
@flake8ext
|
||||
def use_jsonutils(logical_line, filename):
|
||||
"""N321 - Use jsonutils instead of json."""
|
||||
@ -407,7 +387,6 @@ def check_no_sqlalchemy_event_import(logical_line, filename, noqa):
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(validate_log_translations)
|
||||
register(use_jsonutils)
|
||||
register(check_assert_called_once_with)
|
||||
register(no_translate_debug_logs)
|
||||
|
@ -36,39 +36,6 @@ class HackingTestCase(base.BaseTestCase):
|
||||
def assertLineFails(self, func, line):
|
||||
self.assertIsInstance(next(func(line)), tuple)
|
||||
|
||||
def test_log_translations(self):
|
||||
expected_marks = {
|
||||
'error': '_LE',
|
||||
'info': '_LI',
|
||||
'warning': '_LW',
|
||||
'critical': '_LC',
|
||||
'exception': '_LE',
|
||||
}
|
||||
logs = expected_marks.keys()
|
||||
debug = "LOG.debug('OK')"
|
||||
self.assertEqual(
|
||||
0, len(list(checks.validate_log_translations(debug, debug, 'f'))))
|
||||
for log in logs:
|
||||
bad = 'LOG.%s(_("Bad"))' % log
|
||||
self.assertEqual(
|
||||
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
|
||||
bad = 'LOG.%s("Bad")' % log
|
||||
self.assertEqual(
|
||||
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
|
||||
ok = "LOG.%s('OK') # noqa" % log
|
||||
self.assertEqual(
|
||||
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
|
||||
ok = "LOG.%s(variable)" % log
|
||||
self.assertEqual(
|
||||
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
|
||||
|
||||
for mark in checks._all_hints:
|
||||
stmt = "LOG.%s(%s('test'))" % (log, mark)
|
||||
self.assertEqual(
|
||||
0 if expected_marks[log] == mark else 1,
|
||||
len(list(checks.validate_log_translations(stmt, stmt,
|
||||
'f'))))
|
||||
|
||||
def test_no_translate_debug_logs(self):
|
||||
for hint in checks._all_hints:
|
||||
bad = "LOG.debug(%s('bad'))" % hint
|
||||
|
Loading…
Reference in New Issue
Block a user