- [N319] Validate that debug level logs are not translated
- [N320] Validate that LOG messages, except debug ones, have translations
- [N321] Validate that jsonutils module is used instead of json
-- [N322] We do not use @authors tags in source files. We have git to track
- authorship.
-- [N323] Detect common errors with assert_called_once_with
+- [N322] Detect common errors with assert_called_once_with
Creating Unit Tests
-------------------
# - Add test cases for each new rule to
# neutron/tests/unit/test_hacking.py
-author_tag_re = re.compile(r"^\s*#\s*@?[aA]uthor|^\.\.\s+moduleauthor::")
-
_all_log_levels = {
# NOTE(yamamoto): Following nova which uses _() for audit.
'audit': '_',
yield (pos, msg % {'fun': f[:-1]})
-def no_author_tags(physical_line):
- if author_tag_re.match(physical_line):
- physical_line = physical_line.lower()
- pos = physical_line.find('moduleauthor')
- if pos < 0:
- pos = physical_line.find('author')
- return pos, "N322: Don't use author tags"
-
-
def no_translate_debug_logs(logical_line, filename):
"""Check for 'LOG.debug(_(' and 'LOG.debug(_Lx('
if '.assert_called_once_with(' in logical_line:
return
if '.assertcalledonce' in logical_line.lower().replace('_', ''):
- msg = ("N323: Possible use of no-op mock method. "
+ msg = ("N322: Possible use of no-op mock method. "
"please use assert_called_once_with.")
yield (0, msg)
def factory(register):
register(validate_log_translations)
register(use_jsonutils)
- register(no_author_tags)
register(check_assert_called_once_with)
register(no_translate_debug_logs)
"./neutron/plugins/openvswitch/agent/xenapi/etc/xapi.d/"
"plugins/netwrap"))))
- def test_no_author_tags(self):
- self.assertIsInstance(checks.no_author_tags("# author: pele"), tuple)
- self.assertIsInstance(checks.no_author_tags("# @author: pele"), tuple)
- self.assertIsInstance(checks.no_author_tags("# @Author: pele"), tuple)
- self.assertIsInstance(checks.no_author_tags("# Author: pele"), tuple)
- self.assertIsInstance(checks.no_author_tags("# Author pele"), tuple)
- self.assertIsInstance(checks.no_author_tags(".. moduleauthor:: pele"),
- tuple)
- self.assertEqual(2, checks.no_author_tags("# author: pele")[0])
- self.assertEqual(2, checks.no_author_tags("# Author: pele")[0])
- self.assertEqual(3, checks.no_author_tags(".. moduleauthor:: pele")[0])
-
def test_assert_called_once_with(self):
fail_code1 = """
mock = Mock()
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
-hacking>=0.9.2,<0.10
+hacking>=0.10.0,<0.11
cliff>=1.7.0 # Apache-2.0
coverage>=3.6
# E128 continuation line under-indented for visual indent
# E129 visually indented line with same indent as next logical line
# E265 block comment should start with ‘# ‘
+# H238 old style class declaration, use new style
# H305 imports not grouped correctly
-# H307 like imports should be grouped together
-# H402 one line docstring needs punctuation
# H404 multi line docstring should start with a summary
# H405 multi line docstring summary not separated with an empty line
-# H904 Wrap long lines in parentheses instead of a backslash
-ignore = E125,E126,E128,E129,E265,H305,H307,H402,H404,H405,H904
+# W292 no newline at end of file
+ignore = E125,E126,E128,E129,E265,H238,H305,H404,H405,W292
show-source = true
builtins = _
# TODO(dougw) neutron/tests/unit/vmware exclusion is a temporary services split hack