Merge "[hacking] N373 do not use eventlet primitives"
This commit is contained in:
@@ -77,6 +77,8 @@ Nova Specific Commandments
|
|||||||
- [N370] Don't use or import six
|
- [N370] Don't use or import six
|
||||||
- [N371] You must explicitly import python's mock: ``from unittest import mock``
|
- [N371] You must explicitly import python's mock: ``from unittest import mock``
|
||||||
- [N372] Don't use the setDaemon method. Use the daemon attribute instead.
|
- [N372] Don't use the setDaemon method. Use the daemon attribute instead.
|
||||||
|
- [N373] Don't use eventlet specific concurrency primitives. Use the one
|
||||||
|
from stdlib instead. E.g. eventlet.sleep => time.sleep
|
||||||
|
|
||||||
Creating Unit Tests
|
Creating Unit Tests
|
||||||
-------------------
|
-------------------
|
||||||
|
@@ -143,6 +143,8 @@ rwlock_re = re.compile(
|
|||||||
six_re = re.compile(r"^(import six(\..*)?|from six(\..*)? import .*)$")
|
six_re = re.compile(r"^(import six(\..*)?|from six(\..*)? import .*)$")
|
||||||
# Regex for catching the setDaemon method
|
# Regex for catching the setDaemon method
|
||||||
set_daemon_re = re.compile(r"\.setDaemon\(")
|
set_daemon_re = re.compile(r"\.setDaemon\(")
|
||||||
|
eventlet_stdlib_primitives_re = re.compile(
|
||||||
|
r".*(eventlet|greenthread)\.sleep\(.*")
|
||||||
|
|
||||||
|
|
||||||
class BaseASTChecker(ast.NodeVisitor):
|
class BaseASTChecker(ast.NodeVisitor):
|
||||||
@@ -1099,3 +1101,20 @@ def check_set_daemon(logical_line):
|
|||||||
if res:
|
if res:
|
||||||
yield (0, "N372: Don't use the setDaemon method. "
|
yield (0, "N372: Don't use the setDaemon method. "
|
||||||
"Use the daemon attribute instead.")
|
"Use the daemon attribute instead.")
|
||||||
|
|
||||||
|
|
||||||
|
@core.flake8ext
|
||||||
|
def check_eventlet_primitives(logical_line, filename):
|
||||||
|
"""Check for use of any eventlet primitives where the stdlib equivalent
|
||||||
|
should be used
|
||||||
|
|
||||||
|
N373
|
||||||
|
"""
|
||||||
|
msg = (
|
||||||
|
"N373: Use the stdlib concurrency primitive instead of the Eventelt "
|
||||||
|
"specific one")
|
||||||
|
|
||||||
|
match = re.match(eventlet_stdlib_primitives_re, logical_line)
|
||||||
|
|
||||||
|
if match:
|
||||||
|
yield (0, msg)
|
||||||
|
@@ -1064,3 +1064,20 @@ class HackingTestCase(test.NoDBTestCase):
|
|||||||
self.thread.setdaemon(True)
|
self.thread.setdaemon(True)
|
||||||
"""
|
"""
|
||||||
self._assert_has_no_errors(code, checks.check_set_daemon)
|
self._assert_has_no_errors(code, checks.check_set_daemon)
|
||||||
|
|
||||||
|
def test_check_eventlet_primitives(self):
|
||||||
|
code = """
|
||||||
|
eventlet.sleep(0)
|
||||||
|
eventlet.sleep(1)
|
||||||
|
greenthread.sleep(0)
|
||||||
|
greenthread.sleep(1)
|
||||||
|
"""
|
||||||
|
errors = [(x + 1, 0, 'N373') for x in range(4)]
|
||||||
|
self._assert_has_errors(
|
||||||
|
code, checks.check_eventlet_primitives, expected_errors=errors)
|
||||||
|
|
||||||
|
code = """
|
||||||
|
time.sleep(0)
|
||||||
|
time.sleep(1)
|
||||||
|
"""
|
||||||
|
self._assert_has_no_errors(code, checks.check_eventlet_primitives)
|
||||||
|
1
tox.ini
1
tox.ini
@@ -358,6 +358,7 @@ extension =
|
|||||||
N370 = checks:check_six
|
N370 = checks:check_six
|
||||||
N371 = checks:import_stock_mock
|
N371 = checks:import_stock_mock
|
||||||
N372 = checks:check_set_daemon
|
N372 = checks:check_set_daemon
|
||||||
|
N373 = checks:check_eventlet_primitives
|
||||||
paths =
|
paths =
|
||||||
./nova/hacking
|
./nova/hacking
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user