Drop duplicate hacking check of thrid party mock
hacking now provides H216 check[1] to detect usage of third party mock so the same check can be dropped from the local plugin. [1] b921c4de513c9cc624d6ecf68e4f4493e6e72c0d Change-Id: I0c6f86d1d47554f0127fc6a122f94ec8586964ec
This commit is contained in:
@@ -19,7 +19,6 @@ Manila Specific Commandments
|
||||
with a sequence of key-value pairs.
|
||||
- [M337] Ensure to not use xrange().
|
||||
- [M338] Ensure to not use LOG.warn().
|
||||
- [M339] Ensure 'mock' is not imported/used. Use 'unittest.mock' instead.
|
||||
- [M354] Use oslo_utils.uuidutils to generate UUID instead of uuid4().
|
||||
- [M359] Validate that log messages are not translated.
|
||||
|
||||
|
@@ -51,8 +51,6 @@ dict_constructor_with_list_copy_re = re.compile(r".*\bdict\((\[)?(\(|\[)")
|
||||
assert_no_xrange_re = re.compile(r"\s*xrange\s*\(")
|
||||
assert_True = re.compile(r".*assertEqual\(True, .*\)")
|
||||
no_log_warn = re.compile(r"\s*LOG.warn\(.*")
|
||||
third_party_mock = re.compile(r"^import.mock")
|
||||
from_third_party_mock = re.compile(r"^from.mock.import")
|
||||
|
||||
|
||||
class BaseASTChecker(ast.NodeVisitor):
|
||||
@@ -284,14 +282,3 @@ def no_log_warn_check(logical_line):
|
||||
msg = ("M338: LOG.warn is deprecated, use LOG.warning.")
|
||||
if re.match(no_log_warn, logical_line):
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def no_third_party_mock(logical_line):
|
||||
# We should only use unittest.mock, not the third party mock library that
|
||||
# was needed for py2 support.
|
||||
if (re.match(third_party_mock, logical_line) or
|
||||
re.match(from_third_party_mock, logical_line)):
|
||||
msg = ('M339: Unit tests should use the standard library "mock" '
|
||||
'module, not the third party mock library.')
|
||||
yield (0, msg)
|
||||
|
@@ -247,16 +247,6 @@ class HackingTestCase(test.TestCase):
|
||||
"""
|
||||
self._assert_has_no_errors(code, checks.check_uuid4)
|
||||
|
||||
@ddt.unpack
|
||||
@ddt.data(
|
||||
(1, 'import mock'),
|
||||
(0, 'from unittest import mock'),
|
||||
(1, 'from mock import patch'),
|
||||
(0, 'from unittest.mock import patch'))
|
||||
def test_no_third_party_mock(self, err_count, line):
|
||||
self.assertEqual(err_count,
|
||||
len(list(checks.no_third_party_mock(line))))
|
||||
|
||||
def test_no_log_warn_check(self):
|
||||
self.assertEqual(0, len(list(checks.no_log_warn_check(
|
||||
"LOG.warning('This should not trigger LOG.warn "
|
||||
|
Reference in New Issue
Block a user