# imports, we will need to add them to the regex below.
oslo_namespace_imports = re.compile(r"from[\s]*oslo[.](concurrency|db"
"|config|utils|serialization|log)")
+ no_contextlib_nested = re.compile(r"\s*with (contextlib\.)?nested\(")
+log_translation_LI = re.compile(
+ r"(.)*LOG\.(info)\(\s*(_\(|'|\")")
+log_translation_LE = re.compile(
+ r"(.)*LOG\.(exception|error)\(\s*(_\(|'|\")")
+log_translation_LW = re.compile(
+ r"(.)*LOG\.(warning|warn)\(\s*(_\(|'|\")")
+
def no_vi_headers(physical_line, line_number, lines):
"""Check for vi editor configuration in source files.
def test_no_contextlib_nested(self):
self.assertEqual(1, len(list(checks.check_no_contextlib_nested(
"with contextlib.nested("))))
+ self.assertEqual(1, len(list(checks.check_no_contextlib_nested(
+ " with nested("))))
+ self.assertEqual(0, len(list(checks.check_no_contextlib_nested(
+ "with my.nested("))))
self.assertEqual(0, len(list(checks.check_no_contextlib_nested(
"with foo as bar"))))
+
+ def test_check_datetime_now(self):
+ self.assertEqual(1, len(list(checks.check_datetime_now(
+ "datetime.now", False))))
+ self.assertEqual(0, len(list(checks.check_datetime_now(
+ "timeutils.utcnow", False))))
+
+ def test_check_datetime_now_noqa(self):
+ self.assertEqual(0, len(list(checks.check_datetime_now(
+ "datetime.now() # noqa", True))))
+
+ def test_validate_log_translations(self):
+ self.assertEqual(1, len(list(checks.validate_log_translations(
+ "LOG.info('foo')", "foo.py"))))
+ self.assertEqual(1, len(list(checks.validate_log_translations(
+ "LOG.warning('foo')", "foo.py"))))
+ self.assertEqual(1, len(list(checks.validate_log_translations(
+ "LOG.error('foo')", "foo.py"))))
+ self.assertEqual(1, len(list(checks.validate_log_translations(
+ "LOG.exception('foo')", "foo.py"))))
+ self.assertEqual(0, len(list(checks.validate_log_translations(
+ "LOG.info('foo')", "cinder/tests/foo.py"))))
+ self.assertEqual(0, len(list(checks.validate_log_translations(
+ "LOG.info(_LI('foo')", "foo.py"))))
+ self.assertEqual(0, len(list(checks.validate_log_translations(
+ "LOG.warning(_LW('foo')", "foo.py"))))
+ self.assertEqual(0, len(list(checks.validate_log_translations(
+ "LOG.error(_LE('foo')", "foo.py"))))
+ self.assertEqual(0, len(list(checks.validate_log_translations(
+ "LOG.exception(_LE('foo')", "foo.py"))))