Remove duplicated hacking rule
Remove the hacking rule: CheckForAssertingNoneEquality and enable H203. http://git.openstack.org/cgit/openstack-dev/hacking/tree/HACKING.rst Change-Id: Id5c76e4befde163cfce3badbcd329e94485daed3
This commit is contained in:
parent
e4c0c8deef
commit
6ac9254bc4
@ -114,38 +114,6 @@ def block_comments_begin_with_a_space(physical_line, line_number):
|
|||||||
return physical_line.index('#'), MESSAGE
|
return physical_line.index('#'), MESSAGE
|
||||||
|
|
||||||
|
|
||||||
class CheckForAssertingNoneEquality(BaseASTChecker):
|
|
||||||
"""Ensure that code does not use a None with assert(Not*)Equal."""
|
|
||||||
|
|
||||||
CHECK_DESC_IS = ('K003 Use self.assertIsNone(...) when comparing '
|
|
||||||
'against None')
|
|
||||||
CHECK_DESC_ISNOT = ('K004 Use assertIsNotNone(...) when comparing '
|
|
||||||
' against None')
|
|
||||||
|
|
||||||
def visit_Call(self, node):
|
|
||||||
# NOTE(dstanek): I wrote this in a verbose way to make it easier to
|
|
||||||
# read for those that have little experience with Python's AST.
|
|
||||||
|
|
||||||
def _is_None(node):
|
|
||||||
if six.PY3:
|
|
||||||
return (isinstance(node, ast.NameConstant)
|
|
||||||
and node.value is None)
|
|
||||||
else:
|
|
||||||
return isinstance(node, ast.Name) and node.id == 'None'
|
|
||||||
|
|
||||||
if isinstance(node.func, ast.Attribute):
|
|
||||||
if node.func.attr == 'assertEqual':
|
|
||||||
for arg in node.args:
|
|
||||||
if _is_None(arg):
|
|
||||||
self.add_error(node, message=self.CHECK_DESC_IS)
|
|
||||||
elif node.func.attr == 'assertNotEqual':
|
|
||||||
for arg in node.args:
|
|
||||||
if _is_None(arg):
|
|
||||||
self.add_error(node, message=self.CHECK_DESC_ISNOT)
|
|
||||||
|
|
||||||
super(CheckForAssertingNoneEquality, self).generic_visit(node)
|
|
||||||
|
|
||||||
|
|
||||||
class CheckForTranslationIssues(BaseASTChecker):
|
class CheckForTranslationIssues(BaseASTChecker):
|
||||||
|
|
||||||
LOGGING_CHECK_DESC = 'K005 Using translated string in logging'
|
LOGGING_CHECK_DESC = 'K005 Using translated string in logging'
|
||||||
@ -399,6 +367,5 @@ def dict_constructor_with_sequence_copy(logical_line):
|
|||||||
def factory(register):
|
def factory(register):
|
||||||
register(CheckForMutableDefaultArgs)
|
register(CheckForMutableDefaultArgs)
|
||||||
register(block_comments_begin_with_a_space)
|
register(block_comments_begin_with_a_space)
|
||||||
register(CheckForAssertingNoneEquality)
|
|
||||||
register(CheckForTranslationIssues)
|
register(CheckForTranslationIssues)
|
||||||
register(dict_constructor_with_sequence_copy)
|
register(dict_constructor_with_sequence_copy)
|
||||||
|
@ -80,17 +80,6 @@ class TestBlockCommentsBeginWithASpace(BaseStyleCheck):
|
|||||||
self.assert_has_errors(code, expected_errors=errors)
|
self.assert_has_errors(code, expected_errors=errors)
|
||||||
|
|
||||||
|
|
||||||
class TestAssertingNoneEquality(BaseStyleCheck):
|
|
||||||
|
|
||||||
def get_checker(self):
|
|
||||||
return checks.CheckForAssertingNoneEquality
|
|
||||||
|
|
||||||
def test(self):
|
|
||||||
code = self.code_ex.asserting_none_equality['code']
|
|
||||||
errors = self.code_ex.asserting_none_equality['expected_errors']
|
|
||||||
self.assert_has_errors(code, expected_errors=errors)
|
|
||||||
|
|
||||||
|
|
||||||
class TestTranslationChecks(BaseStyleCheck):
|
class TestTranslationChecks(BaseStyleCheck):
|
||||||
|
|
||||||
def get_checker(self):
|
def get_checker(self):
|
||||||
|
1
tox.ini
1
tox.ini
@ -99,6 +99,7 @@ passenv =
|
|||||||
[flake8]
|
[flake8]
|
||||||
filename= *.py,keystone-manage
|
filename= *.py,keystone-manage
|
||||||
show-source = true
|
show-source = true
|
||||||
|
enable-extensions = H203
|
||||||
|
|
||||||
# D100: Missing docstring in public module
|
# D100: Missing docstring in public module
|
||||||
# D101: Missing docstring in public class
|
# D101: Missing docstring in public class
|
||||||
|
Loading…
Reference in New Issue
Block a user