Merge "Amend uuid4 hacking rule"

This commit is contained in:
Jenkins 2017-09-06 23:21:19 +00:00 committed by Gerrit Code Review
commit dcad838cb3
2 changed files with 4 additions and 6 deletions

View File

@ -97,6 +97,7 @@ doubled_words_re = re.compile(
log_remove_context = re.compile(
r"(.)*LOG\.(.*)\(.*(context=[_a-zA-Z0-9].*)+.*\)")
return_not_followed_by_space = re.compile(r"^\s*return(?:\(|{|\"|'|#).*$")
uuid4_re = re.compile(r"uuid4\(\)($|[^\.]|\.hex)")
class BaseASTChecker(ast.NodeVisitor):
@ -779,10 +780,7 @@ def check_uuid4(logical_line):
msg = ("N357: Use oslo_utils.uuidutils or uuidsentinel(in case of test "
"cases) to generate UUID instead of uuid4().")
if "uuid4()." in logical_line:
return
if "uuid4()" in logical_line:
if uuid4_re.search(logical_line):
yield (0, msg)

View File

@ -758,12 +758,12 @@ class HackingTestCase(test.NoDBTestCase):
def test_check_uuid4(self):
code = """
fake_uuid = uuid.uuid4()
hex_uuid = uuid.uuid4().hex
"""
errors = [(1, 0, 'N357')]
errors = [(1, 0, 'N357'), (2, 0, 'N357')]
self._assert_has_errors(code, checks.check_uuid4,
expected_errors=errors)
code = """
hex_uuid = uuid.uuid4().hex
int_uuid = uuid.uuid4().int
urn_uuid = uuid.uuid4().urn
variant_uuid = uuid.uuid4().variant