Merge "Changed hacking check prefix 'M' to 'Z'"

This commit is contained in:
Jenkins 2016-12-21 04:12:16 +00:00 committed by Gerrit Code Review
commit a9e0ba7d73
3 changed files with 34 additions and 34 deletions

View File

@ -6,18 +6,18 @@ Read the OpenStack Style Commandments http://docs.openstack.org/developer/hackin
Zun Specific Commandments
-------------------------
- [M302] Change assertEqual(A is not None) by optimal assert like
- [Z302] Change assertEqual(A is not None) by optimal assert like
assertIsNotNone(A).
- [M310] timeutils.utcnow() wrapper must be used instead of direct calls to
- [Z310] timeutils.utcnow() wrapper must be used instead of direct calls to
datetime.datetime.utcnow() to make it easy to override its return value.
- [M316] Change assertTrue(isinstance(A, B)) by optimal assert like
- [Z316] Change assertTrue(isinstance(A, B)) by optimal assert like
assertIsInstance(A, B).
- [M318] Change assertEqual(A, None) or assertEqual(None, A) by optimal assert
- [Z318] Change assertEqual(A, None) or assertEqual(None, A) by optimal assert
like assertIsNone(A)
- [M322] Method's default argument shouldn't be mutable.
- [M323] Change assertEqual(True, A) or assertEqual(False, A) by optimal assert
- [Z322] Method's default argument shouldn't be mutable.
- [Z323] Change assertEqual(True, A) or assertEqual(False, A) by optimal assert
like assertTrue(A) or assertFalse(A)
- [M336] Must use a dict comprehension instead of a dict constructor
- [Z336] Must use a dict comprehension instead of a dict constructor
with a sequence of key-value pairs.
- [M338] Use assertIn/NotIn(A, B) rather than assertEqual(A in B, True/False).
- [M339] Don't use xrange()
- [Z338] Use assertIn/NotIn(A, B) rather than assertEqual(A in B, True/False).
- [Z339] Don't use xrange()

View File

@ -20,11 +20,11 @@ Guidelines for writing new hacking checks
- Use only for Zun specific tests. OpenStack general tests
should be submitted to the common 'hacking' module.
- Pick numbers in the range M3xx. Find the current test with
- Pick numbers in the range Z3xx. Find the current test with
the highest allocated number and then pick the next value.
If nova has an N3xx code for that test, use the same number.
- Keep the test method code in the source file ordered based
on the M3xx value.
on the Z3xx value.
- List the new rule in the top level HACKING.rst file
- Add test cases for each new rule to zun/tests/unit/test_hacking.py
@ -56,9 +56,9 @@ assert_xrange_re = re.compile(
def assert_equal_none(logical_line):
"""Check for assertEqual(A, None) or assertEqual(None, A) sentences
M318
Z318
"""
msg = ("M318: assertEqual(A, None) or assertEqual(None, A) "
msg = ("Z318: assertEqual(A, None) or assertEqual(None, A) "
"sentences not allowed")
res = (assert_equal_start_with_none_re.match(logical_line) or
assert_equal_end_with_none_re.match(logical_line))
@ -67,7 +67,7 @@ def assert_equal_none(logical_line):
def no_mutable_default_args(logical_line):
msg = "M322: Method's default argument shouldn't be mutable!"
msg = "Z322: Method's default argument shouldn't be mutable!"
if mutable_default_args.match(logical_line):
yield (0, msg)
@ -75,18 +75,18 @@ def no_mutable_default_args(logical_line):
def assert_equal_true_or_false(logical_line):
"""Check for assertEqual(True, A) or assertEqual(False, A) sentences
M323
Z323
"""
res = (assert_equal_with_true_re.search(logical_line) or
assert_equal_with_false_re.search(logical_line))
if res:
yield (0, "M323: assertEqual(True, A) or assertEqual(False, A) "
yield (0, "Z323: assertEqual(True, A) or assertEqual(False, A) "
"sentences not allowed")
def assert_equal_not_none(logical_line):
"""Check for assertEqual(A is not None) sentences M302"""
msg = "M302: assertEqual(A is not None) sentences not allowed."
"""Check for assertEqual(A is not None) sentences Z302"""
msg = "Z302: assertEqual(A is not None) sentences not allowed."
res = asse_equal_with_is_not_none_re.search(logical_line)
if res:
yield (0, msg)
@ -95,21 +95,21 @@ def assert_equal_not_none(logical_line):
def assert_true_isinstance(logical_line):
"""Check for assertTrue(isinstance(a, b)) sentences
M316
Z316
"""
if assert_true_isinstance_re.match(logical_line):
yield (0, "M316: assertTrue(isinstance(a, b)) sentences not allowed")
yield (0, "Z316: assertTrue(isinstance(a, b)) sentences not allowed")
def assert_equal_in(logical_line):
"""Check for assertEqual(True|False, A in B), assertEqual(A in B, True|False)
M338
Z338
"""
res = (assert_equal_in_start_with_true_or_false_re.search(logical_line) or
assert_equal_in_end_with_true_or_false_re.search(logical_line))
if res:
yield (0, "M338: Use assertIn/NotIn(A, B) rather than "
yield (0, "Z338: Use assertIn/NotIn(A, B) rather than "
"assertEqual(A in B, True/False) when checking collection "
"contents.")
@ -117,10 +117,10 @@ def assert_equal_in(logical_line):
def no_xrange(logical_line):
"""Disallow 'xrange()'
M339
Z339
"""
if assert_xrange_re.match(logical_line):
yield(0, "M339: Do not use xrange().")
yield(0, "Z339: Do not use xrange().")
def use_timeutils_utcnow(logical_line, filename):
@ -128,7 +128,7 @@ def use_timeutils_utcnow(logical_line, filename):
if "/tools/" in filename:
return
msg = "M310: timeutils.utcnow() must be used instead of datetime.%s()"
msg = "Z310: timeutils.utcnow() must be used instead of datetime.%s()"
datetime_funcs = ['now', 'utcnow']
for f in datetime_funcs:
pos = logical_line.find('datetime.%s' % f)
@ -137,7 +137,7 @@ def use_timeutils_utcnow(logical_line, filename):
def dict_constructor_with_list_copy(logical_line):
msg = ("M336: Must use a dict comprehension instead of a dict constructor"
msg = ("Z336: Must use a dict comprehension instead of a dict constructor"
" with a sequence of key-value pairs."
)
if dict_constructor_with_list_copy_re.match(logical_line):

View File

@ -78,7 +78,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_errors(code, checker, filename=filename)
def test_assert_equal_in(self):
errors = [(1, 0, "M338")]
errors = [(1, 0, "Z338")]
check = checks.assert_equal_in
code = "self.assertEqual(a in b, True)"
@ -118,7 +118,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_no_errors(code, check)
def test_assert_equal_none(self):
errors = [(1, 0, "M318")]
errors = [(1, 0, "Z318")]
check = checks.assert_equal_none
code = "self.assertEqual(A, None)"
@ -131,7 +131,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_no_errors(code, check)
def test_assert_equal_true_or_false(self):
errors = [(1, 0, "M323")]
errors = [(1, 0, "Z323")]
check = checks.assert_equal_true_or_false
code = "self.assertEqual(True, A)"
@ -147,7 +147,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_no_errors(code, check)
def test_no_mutable_default_args(self):
errors = [(1, 0, "M322")]
errors = [(1, 0, "Z322")]
check = checks.no_mutable_default_args
code = "def get_info_from_bdm(virt_type, bdm, mapping=[])"
@ -160,7 +160,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_no_errors(code, check)
def test_assert_is_not_none(self):
errors = [(1, 0, "M302")]
errors = [(1, 0, "Z302")]
check = checks.assert_equal_not_none
code = "self.assertEqual(A is not None)"
@ -170,7 +170,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_no_errors(code, check)
def test_assert_true_isinstance(self):
errors = [(1, 0, "M316")]
errors = [(1, 0, "Z316")]
check = checks.assert_true_isinstance
code = "self.assertTrue(isinstance(e, exception.BuilAbortException))"
@ -180,7 +180,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_no_errors(code, check)
def test_no_xrange(self):
errors = [(1, 0, "M339")]
errors = [(1, 0, "Z339")]
check = checks.no_xrange
code = "xrange(45)"
@ -190,7 +190,7 @@ class HackingTestCase(base.BaseTestCase):
self._assert_has_no_errors(code, check)
def test_use_timeunitls_utcow(self):
errors = [(1, 0, "M310")]
errors = [(1, 0, "Z310")]
check = checks.use_timeutils_utcnow
code = "datetime.now"