Add hacking rules for CLI import
In order to make Rally as a Service, rally CLI modules do not allow to work with rally.common.db and rally.common.objects. This patch add hacking rule to check the import of CLI module. Change-Id: I31b53567902010182a30fc139308d17beb30bc38
This commit is contained in:
parent
a5c301e8a3
commit
04d5d85f2d
@ -28,3 +28,4 @@ Rally Specific Commandments
|
||||
* [N352] - Ensure that string formatting only uses a mapping if multiple mapping keys are used.
|
||||
* [N353] - Ensure that unicode() function is not uset because of absence in py3
|
||||
* [N354] - Ensure that ``:raises: Exception`` is not used
|
||||
* [N355] - Ensure that CLI modules do not work with ``rally.common.db`` and ``rally.common.objects``
|
||||
|
@ -61,6 +61,8 @@ re_str_format = re.compile(r"""
|
||||
""", re.X)
|
||||
re_raises = re.compile(
|
||||
r"\s:raise[^s] *.*$|\s:raises *:.*$|\s:raises *[^:]+$")
|
||||
re_import_common_db_or_objects = re.compile(
|
||||
r"^from rally.common import (db|objects)")
|
||||
|
||||
|
||||
def skip_ignored_lines(func):
|
||||
@ -462,6 +464,20 @@ def check_raises(physical_line, filename):
|
||||
"in docstrings.")
|
||||
|
||||
|
||||
@skip_ignored_lines
|
||||
def check_import_of_cli(logical_line, filename):
|
||||
"""Check imports of CLI module
|
||||
|
||||
N355
|
||||
"""
|
||||
ignored_files = ["./rally/cli/manage.py", "./rally/cli/commands/show.py"]
|
||||
|
||||
if filename.startswith("./rally/cli") and filename not in ignored_files:
|
||||
if re_import_common_db_or_objects.search(logical_line):
|
||||
yield (0, "N355 CLI modules do not allow to work with "
|
||||
"`rally.common.db`` and ``rally.common.objects`.")
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_assert_methods_from_mock)
|
||||
register(check_import_of_logging)
|
||||
@ -479,3 +495,4 @@ def factory(register):
|
||||
register(check_dict_formatting_in_string)
|
||||
register(check_using_unicode)
|
||||
register(check_raises)
|
||||
register(check_import_of_cli)
|
||||
|
@ -328,3 +328,12 @@ class HackingTestCase(test.TestCase):
|
||||
checkres = checks.check_raises(
|
||||
"text = :raises Exception: if conditions", "fakefile")
|
||||
self.assertIsNone(checkres)
|
||||
|
||||
def test_check_import_of_cli(self):
|
||||
checkres = checks.check_import_of_cli(
|
||||
"from rally.common import db", "fakefile")
|
||||
self.assertIsNotNone(checkres)
|
||||
|
||||
checkres = checks.check_import_of_cli(
|
||||
"from rally.common import objects", "fakefile")
|
||||
self.assertIsNotNone(checkres)
|
||||
|
Loading…
x
Reference in New Issue
Block a user