]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Merge "Fixes nits in check_no_contextlib_nested"
authorJenkins <jenkins@review.openstack.org>
Sun, 5 Apr 2015 18:31:45 +0000 (18:31 +0000)
committerGerrit Code Review <review@openstack.org>
Sun, 5 Apr 2015 18:31:45 +0000 (18:31 +0000)
1  2 
cinder/hacking/checks.py
cinder/tests/test_hacking.py

index 05c585d7d6e3c47f8eac8f2d2bfbdd168d4d5e75,762d7a09921c5ed8385aa5cafb2a481b420d522a..fb7088cb5b972211a423e3e680b13c8ca92e8e66
@@@ -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.
index db69b8a1a148d5fc4dd5343378afd48050dacea8,32e57e2a5686b304207fb1563e63884df4471ef0..ed0a4ca3325421b90cd25839b3dad0e2965c225c
@@@ -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"))))