Merge "autospec check: Allow 'wraps' to be an alternative to autospec"
This commit is contained in:
@@ -339,7 +339,9 @@ exception possible should be used.
|
|||||||
not force them to use ``autospec=True``, but requires that they define some
|
not force them to use ``autospec=True``, but requires that they define some
|
||||||
value for ``autospec``, ``spec``, or ``spec_set``. It could be
|
value for ``autospec``, ``spec``, or ``spec_set``. It could be
|
||||||
``autospec=False``. We just want them to make a conscious decision on using
|
``autospec=False``. We just want them to make a conscious decision on using
|
||||||
or not using ``autospec``.
|
or not using ``autospec``. If any of the following are used then ``autospec``
|
||||||
|
will not be required: ``new``, ``new_callable``, ``spec``, ``spec_set``,
|
||||||
|
``wraps``
|
||||||
|
|
||||||
OpenStack Trademark
|
OpenStack Trademark
|
||||||
-------------------
|
-------------------
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class MockAutospecCheck(object):
|
|||||||
Okay: mock.patch('target_module_1', defined_mock)
|
Okay: mock.patch('target_module_1', defined_mock)
|
||||||
Okay: mock.patch('target_module_1', spec=1000)
|
Okay: mock.patch('target_module_1', spec=1000)
|
||||||
Okay: mock.patch('target_module_1', spec_set=['data'])
|
Okay: mock.patch('target_module_1', spec_set=['data'])
|
||||||
|
Okay: mock.patch('target_module_1', wraps=some_obj)
|
||||||
|
|
||||||
H210: mock.patch('target_module_1')
|
H210: mock.patch('target_module_1')
|
||||||
Okay: mock.patch('target_module_1') # noqa
|
Okay: mock.patch('target_module_1') # noqa
|
||||||
@@ -43,6 +44,8 @@ class MockAutospecCheck(object):
|
|||||||
Okay: mock.patch.object('target_module_2', 'attribute', new_callable=AFunc)
|
Okay: mock.patch.object('target_module_2', 'attribute', new_callable=AFunc)
|
||||||
Okay: mock.patch.object('target_module_2', 'attribute', spec=3)
|
Okay: mock.patch.object('target_module_2', 'attribute', spec=3)
|
||||||
Okay: mock.patch.object('target_module_2', 'attribute', spec_set=[3])
|
Okay: mock.patch.object('target_module_2', 'attribute', spec_set=[3])
|
||||||
|
Okay: mock.patch.object('target_module_2', 'attribute', wraps=some_obj)
|
||||||
|
|
||||||
|
|
||||||
H210: mock.patch.object('target_module_2', 'attribute', somearg=2)
|
H210: mock.patch.object('target_module_2', 'attribute', somearg=2)
|
||||||
H210: mock.patch.object('target_module_2', 'attribute')
|
H210: mock.patch.object('target_module_2', 'attribute')
|
||||||
@@ -67,7 +70,8 @@ class MockCheckVisitor(ast.NodeVisitor):
|
|||||||
# Patchers we are looking for and minimum number of 'args' without
|
# Patchers we are looking for and minimum number of 'args' without
|
||||||
# 'autospec' to not be flagged
|
# 'autospec' to not be flagged
|
||||||
patchers = {'mock.patch': 2, 'mock.patch.object': 3}
|
patchers = {'mock.patch': 2, 'mock.patch.object': 3}
|
||||||
spec_keywords = {"autospec", "new", "new_callable", "spec", "spec_set"}
|
spec_keywords = {"autospec", "new", "new_callable", "spec", "spec_set",
|
||||||
|
"wraps"}
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
super(MockCheckVisitor, self).__init__()
|
super(MockCheckVisitor, self).__init__()
|
||||||
|
|||||||
Reference in New Issue
Block a user