"\(\s*_\(\s*('|\")")
string_translation = re.compile(r"(.)*_\(\s*('|\")")
vi_header_re = re.compile(r"^#\s+vim?:.+")
-underscore_import_check = re.compile(r"(.)*i18n\s+import\s+_(.)*")
+underscore_import_check = re.compile(r"(.)*i18n\s+import(.)* _$")
+underscore_import_check_multi = re.compile(r"(.)*i18n\s+import(.)* _, (.)*")
# We need this for cases where they have created their own _ function.
custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*")
no_audit_log = re.compile(r"(.)*LOG\.audit(.)*")
if file in filename:
return
if (underscore_import_check.match(logical_line) or
+ underscore_import_check_multi.match(logical_line) or
custom_underscore_check.match(logical_line)):
UNDERSCORE_IMPORT_FILES.append(filename)
elif(translated_log.match(logical_line) or
"msg = _('My message')",
"cinder.tests.unit/other_files.py"))))
self.assertEqual(0, len(list(checks.check_explicit_underscore_import(
- "from cinder.i18n import _, _LW",
+ "from cinder.i18n import _LE, _, _LW",
"cinder.tests.unit/other_files2.py"))))
self.assertEqual(0, len(list(checks.check_explicit_underscore_import(
"msg = _('My message')",
self.assertEqual(0, len(list(checks.check_explicit_underscore_import(
"LOG.info('My info message')",
"cinder.tests.unit/other_files4.py"))))
+ self.assertEqual(0, len(list(checks.check_explicit_underscore_import(
+ "from cinder.i18n import _LW",
+ "cinder.tests.unit/other_files5.py"))))
+ self.assertEqual(1, len(list(checks.check_explicit_underscore_import(
+ "msg = _('My message')",
+ "cinder.tests.unit/other_files5.py"))))
# We are patching pep8 so that only the check under test is actually
# installed.