Remove duplicated hacking rule M318,M319
Change-Id: If0fbeb3f0bf826cac3700ad7f244fc059e83718f closes-Bug: #1696628
This commit is contained in:
parent
24510b20e2
commit
014da56bbb
@ -14,10 +14,6 @@ Magnum Specific Commandments
|
|||||||
datetime.datetime.utcnow() to make it easy to override its return value.
|
datetime.datetime.utcnow() to make it easy to override its return value.
|
||||||
- [M316] Change assertTrue(isinstance(A, B)) by optimal assert like
|
- [M316] Change assertTrue(isinstance(A, B)) by optimal assert like
|
||||||
assertIsInstance(A, B).
|
assertIsInstance(A, B).
|
||||||
- [M318] Change assertEqual(A, None) or assertEqual(None, A) by optimal assert
|
|
||||||
like assertIsNone(A)
|
|
||||||
- [M319] Change assertNotEqual(A, None) or assertNotEqual(None, A)
|
|
||||||
by optimal assert like assertIsNotNone(A)
|
|
||||||
- [M322] Method's default argument shouldn't be mutable.
|
- [M322] Method's default argument shouldn't be mutable.
|
||||||
- [M323] Change assertEqual(True, A) or assertEqual(False, A) by optimal assert
|
- [M323] Change assertEqual(True, A) or assertEqual(False, A) by optimal assert
|
||||||
like assertTrue(A) or assertFalse(A)
|
like assertTrue(A) or assertFalse(A)
|
||||||
|
@ -38,14 +38,6 @@ assert_equal_in_end_with_true_or_false_re = re.compile(
|
|||||||
r"assertEqual\((\w|[][.'\"])+ in (\w|[][.'\", ])+, (True|False)\)")
|
r"assertEqual\((\w|[][.'\"])+ in (\w|[][.'\", ])+, (True|False)\)")
|
||||||
assert_equal_in_start_with_true_or_false_re = re.compile(
|
assert_equal_in_start_with_true_or_false_re = re.compile(
|
||||||
r"assertEqual\((True|False), (\w|[][.'\"])+ in (\w|[][.'\", ])+\)")
|
r"assertEqual\((True|False), (\w|[][.'\"])+ in (\w|[][.'\", ])+\)")
|
||||||
assert_equal_end_with_none_re = re.compile(
|
|
||||||
r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)")
|
|
||||||
assert_equal_start_with_none_re = re.compile(
|
|
||||||
r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
|
|
||||||
assert_not_equal_end_with_none_re = re.compile(
|
|
||||||
r"(.)*assertNotEqual\((\w|\.|\'|\"|\[|\])+, None\)")
|
|
||||||
assert_not_equal_start_with_none_re = re.compile(
|
|
||||||
r"(.)*assertNotEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
|
|
||||||
assert_equal_with_true_re = re.compile(
|
assert_equal_with_true_re = re.compile(
|
||||||
r"assertEqual\(True,")
|
r"assertEqual\(True,")
|
||||||
assert_equal_with_false_re = re.compile(
|
assert_equal_with_false_re = re.compile(
|
||||||
@ -74,32 +66,6 @@ translated_log = re.compile(
|
|||||||
string_translation = re.compile(r"[^_]*_\(\s*('|\")")
|
string_translation = re.compile(r"[^_]*_\(\s*('|\")")
|
||||||
|
|
||||||
|
|
||||||
def assert_equal_none(logical_line):
|
|
||||||
"""Check for assertEqual(A, None) or assertEqual(None, A) sentences
|
|
||||||
|
|
||||||
M318
|
|
||||||
"""
|
|
||||||
msg = ("M318: 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))
|
|
||||||
if res:
|
|
||||||
yield (0, msg)
|
|
||||||
|
|
||||||
|
|
||||||
def assert_not_equal_none(logical_line):
|
|
||||||
"""Check for assertNotEqual(A, None) or assertNotEqual(None, A) sentences
|
|
||||||
|
|
||||||
M319
|
|
||||||
"""
|
|
||||||
msg = ("M319: assertNotEqual(A, None) or assertNotEqual(None, A) "
|
|
||||||
"sentences not allowed")
|
|
||||||
res = (assert_not_equal_start_with_none_re.match(logical_line) or
|
|
||||||
assert_not_equal_end_with_none_re.match(logical_line))
|
|
||||||
if res:
|
|
||||||
yield (0, msg)
|
|
||||||
|
|
||||||
|
|
||||||
def no_mutable_default_args(logical_line):
|
def no_mutable_default_args(logical_line):
|
||||||
msg = "M322: Method's default argument shouldn't be mutable!"
|
msg = "M322: Method's default argument shouldn't be mutable!"
|
||||||
if mutable_default_args.match(logical_line):
|
if mutable_default_args.match(logical_line):
|
||||||
@ -215,8 +181,6 @@ def check_explicit_underscore_import(logical_line, filename):
|
|||||||
|
|
||||||
def factory(register):
|
def factory(register):
|
||||||
register(no_mutable_default_args)
|
register(no_mutable_default_args)
|
||||||
register(assert_equal_none)
|
|
||||||
register(assert_not_equal_none)
|
|
||||||
register(assert_equal_true_or_false)
|
register(assert_equal_true_or_false)
|
||||||
register(assert_equal_not_none)
|
register(assert_equal_not_none)
|
||||||
register(assert_true_isinstance)
|
register(assert_true_isinstance)
|
||||||
|
@ -117,32 +117,6 @@ class HackingTestCase(base.TestCase):
|
|||||||
code = "self.assertEqual(False, any(a==1 for a in b))"
|
code = "self.assertEqual(False, any(a==1 for a in b))"
|
||||||
self._assert_has_no_errors(code, check)
|
self._assert_has_no_errors(code, check)
|
||||||
|
|
||||||
def test_assert_equal_none(self):
|
|
||||||
errors = [(1, 0, "M318")]
|
|
||||||
check = checks.assert_equal_none
|
|
||||||
|
|
||||||
code = "self.assertEqual(A, None)"
|
|
||||||
self._assert_has_errors(code, check, errors)
|
|
||||||
|
|
||||||
code = "self.assertEqual(None, A)"
|
|
||||||
self._assert_has_errors(code, check, errors)
|
|
||||||
|
|
||||||
code = "self.assertIsNone()"
|
|
||||||
self._assert_has_no_errors(code, check)
|
|
||||||
|
|
||||||
def test_assert_not_equal_none(self):
|
|
||||||
errors = [(1, 0, "M319")]
|
|
||||||
check = checks.assert_not_equal_none
|
|
||||||
|
|
||||||
code = "self.assertNotEqual(A, None)"
|
|
||||||
self._assert_has_errors(code, check, errors)
|
|
||||||
|
|
||||||
code = "self.assertNotEqual(None, A)"
|
|
||||||
self._assert_has_errors(code, check, errors)
|
|
||||||
|
|
||||||
code = "self.assertIsNotNone()"
|
|
||||||
self._assert_has_no_errors(code, check)
|
|
||||||
|
|
||||||
def test_assert_equal_true_or_false(self):
|
def test_assert_equal_true_or_false(self):
|
||||||
errors = [(1, 0, "M323")]
|
errors = [(1, 0, "M323")]
|
||||||
check = checks.assert_equal_true_or_false
|
check = checks.assert_equal_true_or_false
|
||||||
|
1
tox.ini
1
tox.ini
@ -131,6 +131,7 @@ commands =
|
|||||||
oslo-config-generator --config-file etc/magnum/magnum-config-generator.conf
|
oslo-config-generator --config-file etc/magnum/magnum-config-generator.conf
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
|
enable-extensions = H203
|
||||||
exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,tools,releasenotes
|
exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,tools,releasenotes
|
||||||
|
|
||||||
[hacking]
|
[hacking]
|
||||||
|
Loading…
Reference in New Issue
Block a user