Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which supports Python 3. Fix problems found. Update local hacking checks for new flake8. Change-Id: I8ba89483c8e6b76011833cfc5080eab3fd269c8b
This commit is contained in:
parent
a229965266
commit
6e6d76aafe
@ -28,6 +28,8 @@ import functools
|
||||
import re
|
||||
import tokenize
|
||||
|
||||
from hacking import core
|
||||
|
||||
re_assert_true_instance = re.compile(
|
||||
r"(.)*assertTrue\(isinstance\((\w|\.|\'|\"|\[|\])+, "
|
||||
r"(\w|\.|\'|\"|\[|\])+\)\)")
|
||||
@ -63,6 +65,7 @@ re_raises = re.compile(
|
||||
r"\s:raise[^s] *.*$|\s:raises *:.*$|\s:raises *[^:]+$")
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def skip_ignored_lines(func):
|
||||
|
||||
@functools.wraps(func)
|
||||
@ -86,6 +89,7 @@ def _parse_assert_mock_str(line):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def check_assert_methods_from_mock(logical_line, filename):
|
||||
"""Ensure that ``assert_*`` methods from ``mock`` library is used correctly
|
||||
|
||||
@ -132,6 +136,7 @@ def check_assert_methods_from_mock(logical_line, filename):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def assert_true_instance(logical_line, filename):
|
||||
"""Check for assertTrue(isinstance(a, b)) sentences
|
||||
|
||||
@ -143,6 +148,7 @@ def assert_true_instance(logical_line, filename):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def assert_equal_type(logical_line, filename):
|
||||
"""Check for assertEqual(type(A), B) sentences
|
||||
|
||||
@ -154,6 +160,7 @@ def assert_equal_type(logical_line, filename):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def assert_equal_none(logical_line, filename):
|
||||
"""Check for assertEqual(A, None) or assertEqual(None, A) sentences
|
||||
|
||||
@ -168,6 +175,7 @@ def assert_equal_none(logical_line, filename):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def assert_true_or_false_with_in(logical_line, filename):
|
||||
"""Check assertTrue/False(A in/not in B) with collection contents
|
||||
|
||||
@ -186,6 +194,7 @@ def assert_true_or_false_with_in(logical_line, filename):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def assert_equal_in(logical_line, filename):
|
||||
"""Check assertEqual(A in/not in B, True/False) with collection contents
|
||||
|
||||
@ -204,6 +213,7 @@ def assert_equal_in(logical_line, filename):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def check_quotes(logical_line, filename):
|
||||
"""Check that single quotation marks are not used
|
||||
|
||||
@ -257,6 +267,7 @@ def check_quotes(logical_line, filename):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def check_no_constructor_data_struct(logical_line, filename):
|
||||
"""Check that data structs (lists, dicts) are declared using literals
|
||||
|
||||
@ -271,6 +282,7 @@ def check_no_constructor_data_struct(logical_line, filename):
|
||||
yield (0, "N351 Remove list() construct and use literal []")
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def check_dict_formatting_in_string(logical_line, tokens):
|
||||
"""Check that strings do not use dict-formatting with a single replacement
|
||||
|
||||
@ -322,7 +334,7 @@ def check_dict_formatting_in_string(logical_line, tokens):
|
||||
format_keys.add(match.group(1))
|
||||
if len(format_keys) == 1:
|
||||
yield (0,
|
||||
"N353 Do not use mapping key string formatting "
|
||||
"N352 Do not use mapping key string formatting "
|
||||
"with a single key")
|
||||
if text != ")":
|
||||
# NOTE(stpierre): You can have a parenthesized string
|
||||
@ -339,6 +351,7 @@ def check_dict_formatting_in_string(logical_line, tokens):
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
@core.flake8ext
|
||||
def check_using_unicode(logical_line, filename):
|
||||
"""Check crosspython unicode usage
|
||||
|
||||
@ -350,6 +363,7 @@ def check_using_unicode(logical_line, filename):
|
||||
"use 'six.text_type' instead.")
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def check_raises(physical_line, filename):
|
||||
"""Check raises usage
|
||||
|
||||
@ -362,17 +376,3 @@ def check_raises(physical_line, filename):
|
||||
if re_raises.search(physical_line):
|
||||
return (0, "N354 ':Please use ':raises Exception: conditions' "
|
||||
"in docstrings.")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_assert_methods_from_mock)
|
||||
register(assert_true_instance)
|
||||
register(assert_equal_type)
|
||||
register(assert_equal_none)
|
||||
register(assert_true_or_false_with_in)
|
||||
register(assert_equal_in)
|
||||
register(check_quotes)
|
||||
register(check_no_constructor_data_struct)
|
||||
register(check_dict_formatting_in_string)
|
||||
register(check_using_unicode)
|
||||
register(check_raises)
|
||||
|
@ -1,4 +1,4 @@
|
||||
hacking>=2.0,<=2.1 # Apache-2.0
|
||||
hacking>=3.0,<3.1.0 # Apache-2.0
|
||||
|
||||
coverage>=4.0 # Apache-2.0
|
||||
ddt>=1.0.1 # MIT
|
||||
|
16
tox.ini
16
tox.ini
@ -63,8 +63,20 @@ show-source = true
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,setup.py,build,releasenotes
|
||||
|
||||
[hacking]
|
||||
local-check-factory = osprofiler.hacking.checks.factory
|
||||
[flake8:local-plugins]
|
||||
extension =
|
||||
N301 = checks:check_assert_methods_from_mock
|
||||
N320 = checks:assert_true_instance
|
||||
N321 = checks:assert_equal_type
|
||||
N322 = checks:assert_equal_none
|
||||
N323 = checks:assert_true_or_false_with_in
|
||||
N324 = checks:assert_equal_in
|
||||
N350 = checks:check_quotes
|
||||
N351 = checks:check_no_constructor_data_struct
|
||||
N352 = checks:check_dict_formatting_in_string
|
||||
N353 = checks:check_using_unicode
|
||||
N354 = checks:check_raises
|
||||
paths = ./osprofiler/hacking
|
||||
|
||||
[testenv:releasenotes]
|
||||
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
|
||||
|
Loading…
Reference in New Issue
Block a user