From: Jenkins Date: Sun, 5 Apr 2015 18:31:45 +0000 (+0000) Subject: Merge "Fixes nits in check_no_contextlib_nested" X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=fd8aa9b9c3446a3eca41d44c08abc4fe05b50a85;p=openstack-build%2Fcinder-build.git Merge "Fixes nits in check_no_contextlib_nested" --- fd8aa9b9c3446a3eca41d44c08abc4fe05b50a85 diff --cc cinder/hacking/checks.py index 05c585d7d,762d7a099..fb7088cb5 --- a/cinder/hacking/checks.py +++ b/cinder/hacking/checks.py @@@ -46,14 -46,8 +46,15 @@@ no_audit_log = re.compile(r"(.)*LOG\.au # 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. diff --cc cinder/tests/test_hacking.py index db69b8a1a,32e57e2a5..ed0a4ca33 --- a/cinder/tests/test_hacking.py +++ b/cinder/tests/test_hacking.py @@@ -167,35 -167,9 +167,39 @@@ class HackingTestCase(test.TestCase) 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"))))