Fix N332 api_version decorator hacking check
We spuriously ran afoul of N332 here [1]. This change set fixes the hacking check to be a little narrower and avoid (at least some) false positives. [1] https://review.openstack.org/#/c/557508/1/nova/tests/unit/volume/test_cinder.py@1014 Change-Id: I8c5e0854141d7c329483d00d26de7078dc756ee0
This commit is contained in:
parent
00b19c73cf
commit
6360fe1175
|
@ -85,7 +85,7 @@ import_translation_for_log_or_exception = re.compile(
|
|||
r"(.)*(from\snova.i18n\simport)\s_")
|
||||
# We need this for cases where they have created their own _ function.
|
||||
custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*")
|
||||
api_version_re = re.compile(r"@.*api_version")
|
||||
api_version_re = re.compile(r"@.*\bapi_version\b")
|
||||
dict_constructor_with_list_copy_re = re.compile(r".*\bdict\((\[)?(\(|\[)")
|
||||
decorator_re = re.compile(r"@.*")
|
||||
http_not_implemented_re = re.compile(r"raise .*HTTPNotImplemented\(")
|
||||
|
|
|
@ -381,13 +381,22 @@ class HackingTestCase(test.NoDBTestCase):
|
|||
expected_errors=[(1, 0, "N335")])
|
||||
|
||||
def test_api_version_decorator_check_no_errors(self):
|
||||
code = """
|
||||
class ControllerClass():
|
||||
@wsgi.api_version("2.5")
|
||||
def my_method():
|
||||
pass
|
||||
"""
|
||||
self._assert_has_no_errors(code, checks.check_api_version_decorator)
|
||||
codelist = [
|
||||
"""
|
||||
class ControllerClass():
|
||||
@wsgi.api_version("2.5")
|
||||
def my_method():
|
||||
pass
|
||||
""",
|
||||
"""
|
||||
@some_other_decorator
|
||||
@mock.patch('foo', return_value=api_versions.APIVersion("2.5"))
|
||||
def my_method():
|
||||
pass
|
||||
"""]
|
||||
for code in codelist:
|
||||
self._assert_has_no_errors(
|
||||
code, checks.check_api_version_decorator)
|
||||
|
||||
def test_trans_add(self):
|
||||
|
||||
|
|
Loading…
Reference in New Issue