Browse Source

Add hacking check for 3rd party mock

Change-Id: I25715d04791e9c8c681a63954719d48f7b390dcd
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
tags/16.0.0.0rc1
Sean McGinnis 3 months ago
parent
commit
eb915e2dbb
No known key found for this signature in database GPG Key ID: CE7EE4BFAF8D70C8
4 changed files with 27 additions and 1 deletions
  1. +15
    -0
      cinder/tests/hacking/checks.py
  2. +10
    -0
      cinder/tests/unit/test_hacking.py
  3. +1
    -1
      cinder/tests/unit/volume/drivers/test_prophetstor_dpl.py
  4. +1
    -0
      tox.ini

+ 15
- 0
cinder/tests/hacking/checks.py View File

@@ -372,3 +372,18 @@ def validate_assertTrue(logical_line, filename):
msg = ("C313: Unit tests should use assertTrue(value) instead"
" of using assertEqual(True, value).")
yield(0, msg)


third_party_mock = re.compile("^import.mock")
from_third_party_mock = re.compile("^from.mock.import")


@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 = ('C337: Unit tests should use the standard library "mock" '
'module, not the third party mock lib.')
yield(0, msg)

+ 10
- 0
cinder/tests/unit/test_hacking.py View File

@@ -293,3 +293,13 @@ class HackingTestCase(test.TestCase):
def test_no_test_log(self, first, second, third, fourth):
self.assertEqual(first, len(list(checks.no_test_log(
"%s('arg')" % second, third, fourth))))

@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))))

+ 1
- 1
cinder/tests/unit/volume/drivers/test_prophetstor_dpl.py View File

@@ -14,8 +14,8 @@

import errno
import re
from unittest import mock

import mock
from oslo_utils import units
from six.moves import http_client



+ 1
- 0
tox.ini View File

@@ -213,6 +213,7 @@ extension =
C312 = checks:no_translate_logs
C313 = checks:validate_assertTrue
C336 = checks:dict_constructor_with_list_copy
C337 = checks:no_third_party_mock
paths = ./cinder/tests/hacking

[doc8]


Loading…
Cancel
Save