Merge "Replace own hacking checks by built-on ones"
This commit is contained in:
commit
0362e79771
@ -10,8 +10,6 @@ Cloudkitty Specific Commandments
|
||||
--------------------------------
|
||||
|
||||
- [C310] Check for improper use of logging format arguments.
|
||||
- [C311] Use assertIsNone(...) instead of assertEqual(None, ...).
|
||||
- [C312] Use assertTrue(...) rather than assertEqual(True, ...).
|
||||
- [C313] Validate that logs are not translated.
|
||||
- [C314] str() and unicode() cannot be used on an exception.
|
||||
- [C315] Translated messages cannot be concatenated. String should be
|
||||
@ -23,7 +21,6 @@ Cloudkitty Specific Commandments
|
||||
- [C320] Do not use LOG.warn as it's deprecated.
|
||||
- [C321] Ensure that the _() function is explicitly imported to ensure
|
||||
proper translations.
|
||||
- [C322] Check for usage of deprecated assertRaisesRegexp
|
||||
|
||||
LOG Translations
|
||||
----------------
|
||||
|
@ -320,30 +320,6 @@ def no_xrange(logical_line):
|
||||
yield (0, "C319: Do not use xrange().")
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def validate_assertTrue(logical_line):
|
||||
"""Use assertTrue instead of assertEqual
|
||||
|
||||
C312
|
||||
"""
|
||||
if re.match(assert_True, logical_line):
|
||||
msg = ("C312: Unit tests should use assertTrue(value) instead"
|
||||
" of using assertEqual(True, value).")
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def validate_assertIsNone(logical_line):
|
||||
"""Use assertIsNone instead of assertEqual
|
||||
|
||||
C311
|
||||
"""
|
||||
if re.match(assert_None, logical_line):
|
||||
msg = ("C311: Unit tests should use assertIsNone(value) instead"
|
||||
" of using assertEqual(None, value).")
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def no_log_warn_check(logical_line):
|
||||
"""Disallow 'LOG.warn'
|
||||
@ -353,15 +329,3 @@ def no_log_warn_check(logical_line):
|
||||
msg = ("C320: LOG.warn is deprecated, please use LOG.warning!")
|
||||
if re.match(no_log_warn, logical_line):
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def assert_raises_regexp(logical_line):
|
||||
"""Check for usage of deprecated assertRaisesRegexp
|
||||
|
||||
C322
|
||||
"""
|
||||
res = asse_raises_regexp.search(logical_line)
|
||||
if res:
|
||||
yield (0, "C322: assertRaisesRegex must be used instead "
|
||||
"of assertRaisesRegexp")
|
||||
|
@ -285,33 +285,9 @@ class HackingTestCase(tests.TestCase):
|
||||
|
||||
self.assertEqual(0, len(list(checks.no_xrange("range(45)"))))
|
||||
|
||||
def test_validate_assertTrue(self):
|
||||
test_value = True
|
||||
self.assertEqual(0, len(list(checks.validate_assertTrue(
|
||||
"assertTrue(True)"))))
|
||||
self.assertEqual(1, len(list(checks.validate_assertTrue(
|
||||
"assertEqual(True, %s)" % test_value))))
|
||||
|
||||
def test_validate_assertIsNone(self):
|
||||
test_value = None
|
||||
self.assertEqual(0, len(list(checks.validate_assertIsNone(
|
||||
"assertIsNone(None)"))))
|
||||
self.assertEqual(1, len(list(checks.validate_assertIsNone(
|
||||
"assertEqual(None, %s)" % test_value))))
|
||||
|
||||
def test_no_log_warn_check(self):
|
||||
self.assertEqual(0, len(list(checks.no_log_warn_check(
|
||||
"LOG.warning('This should not trigger LOG.warn"
|
||||
"hacking check.')"))))
|
||||
self.assertEqual(1, len(list(checks.no_log_warn_check(
|
||||
"LOG.warn('We should not use LOG.wan')"))))
|
||||
|
||||
def test_oslo_assert_raises_regexp(self):
|
||||
code = """
|
||||
self.assertRaisesRegexp(ValueError,
|
||||
"invalid literal for.*XYZ'$",
|
||||
int,
|
||||
'XYZ')
|
||||
"""
|
||||
self._assert_has_errors(code, checks.assert_raises_regexp,
|
||||
expected_errors=[(1, 0, "C322")])
|
||||
|
8
tox.ini
8
tox.ini
@ -82,6 +82,11 @@ commands = {posargs}
|
||||
[flake8]
|
||||
filename = *.py,app.wsgi
|
||||
exclude = .git,.venv,.tox,dist,doc,*egg,build,.ropeproject,releasenotes
|
||||
# [H203]: Use assertIs(Not)None to check for None
|
||||
# [H204]: Use assert(Not)Equal to check for equality
|
||||
# [H205]: Use assert(Greater|Less)(Equal) for comparison
|
||||
enable-extensions=H203,H204,H205
|
||||
|
||||
|
||||
[doc8]
|
||||
ignore-path = .venv,.git,.tox,.tmp,*cloudkitty/locale*,*lib/python*,cloudkitty.egg*,doc/build,releasenotes/*
|
||||
@ -92,8 +97,6 @@ import_exceptions = cloudkitty.i18n
|
||||
[flake8:local-plugins]
|
||||
extension =
|
||||
C310 = checks:CheckLoggingFormatArgs
|
||||
C311 = checks:validate_assertIsNone
|
||||
C312 = checks:validate_assertTrue
|
||||
C313 = checks:no_translate_logs
|
||||
C314 = checks:CheckForStrUnicodeExc
|
||||
C315 = checks:CheckForTransAdd
|
||||
@ -102,7 +105,6 @@ extension =
|
||||
C319 = checks:no_xrange
|
||||
C320 = checks:no_log_warn_check
|
||||
C321 = checks:check_explicit_underscore_import
|
||||
C322 = checks:assert_raises_regexp
|
||||
paths = ./cloudkitty/hacking
|
||||
|
||||
[testenv:releasenotes]
|
||||
|
Loading…
x
Reference in New Issue
Block a user