Skip to content

Commit ab46694

Browse files
committed
Run black and linting
1 parent b4ed5d0 commit ab46694

File tree

5 files changed

+237
-217
lines changed

5 files changed

+237
-217
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ of a test:
1010
.. code-block:: python
1111
1212
import os
13-
13+
1414
class UnixFS:
15-
15+
1616
@staticmethod
1717
def rm(filename):
1818
os.remove(filename)
19-
19+
2020
def test_unix_fs(mocker):
2121
mocker.patch('os.remove')
2222
UnixFS.rm('file')
@@ -44,13 +44,13 @@ of a test:
4444

4545
.. |python| image:: https://img.shields.io/pypi/pyversions/pytest-mock.svg
4646
:target: https://pypi.python.org/pypi/pytest-mock/
47-
48-
47+
48+
4949
.. image:: http://www.opensourcecitizen.org/badge?url=github.com/pytest-dev/pytest-mock
5050
:target: http://www.opensourcecitizen.org/project?url=github.com/pytest-dev/pytest-mock
5151

5252
If you found this library useful, donate some CPU cycles to its
53-
development efforts by clicking above. Thank you! 😇
53+
development efforts by clicking above. Thank you! 😇
5454

5555
Usage
5656
=====
@@ -160,8 +160,8 @@ diff::
160160
E Right contains more items:
161161
E {'bar': 4}
162162
E Use -v to get the full diff
163-
164-
163+
164+
165165
test_foo.py:6: AssertionError
166166
========================== 1 failed in 0.03 seconds ===========================
167167

pytest_mock.py

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ def _get_mock_module(config):
2222
"unittest.mock" for Python 3, but the user can force to always use "mock" on Python 3 using
2323
the mock_use_standalone_module ini option.
2424
"""
25-
if not hasattr(_get_mock_module, '_module'):
26-
use_standalone_module = parse_ini_boolean(config.getini('mock_use_standalone_module'))
25+
if not hasattr(_get_mock_module, "_module"):
26+
use_standalone_module = parse_ini_boolean(
27+
config.getini("mock_use_standalone_module")
28+
)
2729
if sys.version_info[0] == 2 or use_standalone_module:
2830
import mock
31+
2932
_get_mock_module._module = mock
3033
else:
3134
import unittest.mock
35+
3236
_get_mock_module._module = unittest.mock
3337

3438
return _get_mock_module._module
@@ -100,8 +104,7 @@ def spy(self, obj, name):
100104
if isinstance(value, (classmethod, staticmethod)):
101105
autospec = False
102106

103-
result = self.patch.object(obj, name, side_effect=method,
104-
autospec=autospec)
107+
result = self.patch.object(obj, name, side_effect=method, autospec=autospec)
105108
return result
106109

107110
def stub(self, name=None):
@@ -134,7 +137,7 @@ def _start_patch(self, mock_func, *args, **kwargs):
134137
p = mock_func(*args, **kwargs)
135138
mocked = p.start()
136139
self._patches.append(p)
137-
if hasattr(mocked, 'reset_mock'):
140+
if hasattr(mocked, "reset_mock"):
138141
self._mocks.append(mocked)
139142
return mocked
140143

@@ -144,8 +147,7 @@ def object(self, *args, **kwargs):
144147

145148
def multiple(self, *args, **kwargs):
146149
"""API to mock.patch.multiple"""
147-
return self._start_patch(self.mock_module.patch.multiple, *args,
148-
**kwargs)
150+
return self._start_patch(self.mock_module.patch.multiple, *args, **kwargs)
149151

150152
def dict(self, *args, **kwargs):
151153
"""API to mock.patch.dict"""
@@ -173,8 +175,10 @@ def mock(mocker):
173175
Same as "mocker", but kept only for backward compatibility.
174176
"""
175177
import warnings
176-
warnings.warn('"mock" fixture has been deprecated, use "mocker" instead',
177-
DeprecationWarning)
178+
179+
warnings.warn(
180+
'"mock" fixture has been deprecated, use "mocker" instead', DeprecationWarning
181+
)
178182
return mocker
179183

180184

@@ -188,67 +192,60 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
188192
__wrapped_mock_method__(*args, **kwargs)
189193
return
190194
except AssertionError as e:
191-
if getattr(e, '_mock_introspection_applied', 0):
195+
if getattr(e, "_mock_introspection_applied", 0):
192196
msg = text_type(e)
193197
else:
194198
__mock_self = args[0]
195199
msg = text_type(e)
196200
if __mock_self.call_args is not None:
197201
actual_args, actual_kwargs = __mock_self.call_args
198-
msg += '\n\npytest introspection follows:\n'
202+
msg += "\n\npytest introspection follows:\n"
199203
try:
200204
assert actual_args == args[1:]
201205
except AssertionError as e:
202-
msg += '\nArgs:\n' + text_type(e)
206+
msg += "\nArgs:\n" + text_type(e)
203207
try:
204208
assert actual_kwargs == kwargs
205209
except AssertionError as e:
206-
msg += '\nKwargs:\n' + text_type(e)
210+
msg += "\nKwargs:\n" + text_type(e)
207211
e = AssertionError(msg)
208212
e._mock_introspection_applied = True
209213
raise e
210214

211215

212216
def wrap_assert_not_called(*args, **kwargs):
213217
__tracebackhide__ = True
214-
assert_wrapper(_mock_module_originals["assert_not_called"],
215-
*args, **kwargs)
218+
assert_wrapper(_mock_module_originals["assert_not_called"], *args, **kwargs)
216219

217220

218221
def wrap_assert_called_with(*args, **kwargs):
219222
__tracebackhide__ = True
220-
assert_wrapper(_mock_module_originals["assert_called_with"],
221-
*args, **kwargs)
223+
assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs)
222224

223225

224226
def wrap_assert_called_once(*args, **kwargs):
225227
__tracebackhide__ = True
226-
assert_wrapper(_mock_module_originals["assert_called_once"],
227-
*args, **kwargs)
228+
assert_wrapper(_mock_module_originals["assert_called_once"], *args, **kwargs)
228229

229230

230231
def wrap_assert_called_once_with(*args, **kwargs):
231232
__tracebackhide__ = True
232-
assert_wrapper(_mock_module_originals["assert_called_once_with"],
233-
*args, **kwargs)
233+
assert_wrapper(_mock_module_originals["assert_called_once_with"], *args, **kwargs)
234234

235235

236236
def wrap_assert_has_calls(*args, **kwargs):
237237
__tracebackhide__ = True
238-
assert_wrapper(_mock_module_originals["assert_has_calls"],
239-
*args, **kwargs)
238+
assert_wrapper(_mock_module_originals["assert_has_calls"], *args, **kwargs)
240239

241240

242241
def wrap_assert_any_call(*args, **kwargs):
243242
__tracebackhide__ = True
244-
assert_wrapper(_mock_module_originals["assert_any_call"],
245-
*args, **kwargs)
243+
assert_wrapper(_mock_module_originals["assert_any_call"], *args, **kwargs)
246244

247245

248246
def wrap_assert_called(*args, **kwargs):
249247
__tracebackhide__ = True
250-
assert_wrapper(_mock_module_originals["assert_called"],
251-
*args, **kwargs)
248+
assert_wrapper(_mock_module_originals["assert_called"], *args, **kwargs)
252249

253250

254251
def wrap_assert_methods(config):
@@ -263,26 +260,25 @@ def wrap_assert_methods(config):
263260
mock_module = _get_mock_module(config)
264261

265262
wrappers = {
266-
'assert_called': wrap_assert_called,
267-
'assert_called_once': wrap_assert_called_once,
268-
'assert_called_with': wrap_assert_called_with,
269-
'assert_called_once_with': wrap_assert_called_once_with,
270-
'assert_any_call': wrap_assert_any_call,
271-
'assert_has_calls': wrap_assert_has_calls,
272-
'assert_not_called': wrap_assert_not_called,
263+
"assert_called": wrap_assert_called,
264+
"assert_called_once": wrap_assert_called_once,
265+
"assert_called_with": wrap_assert_called_with,
266+
"assert_called_once_with": wrap_assert_called_once_with,
267+
"assert_any_call": wrap_assert_any_call,
268+
"assert_has_calls": wrap_assert_has_calls,
269+
"assert_not_called": wrap_assert_not_called,
273270
}
274271
for method, wrapper in wrappers.items():
275272
try:
276273
original = getattr(mock_module.NonCallableMock, method)
277274
except AttributeError: # pragma: no cover
278275
continue
279276
_mock_module_originals[method] = original
280-
patcher = mock_module.patch.object(
281-
mock_module.NonCallableMock, method, wrapper)
277+
patcher = mock_module.patch.object(mock_module.NonCallableMock, method, wrapper)
282278
patcher.start()
283279
_mock_module_patches.append(patcher)
284280

285-
if hasattr(config, 'add_cleanup'):
281+
if hasattr(config, "add_cleanup"):
286282
add_cleanup = config.add_cleanup
287283
else:
288284
# pytest 2.7 compatibility
@@ -298,26 +294,33 @@ def unwrap_assert_methods():
298294

299295

300296
def pytest_addoption(parser):
301-
parser.addini('mock_traceback_monkeypatch',
302-
'Monkeypatch the mock library to improve reporting of the '
303-
'assert_called_... methods',
304-
default=True)
305-
parser.addini('mock_use_standalone_module',
306-
'Use standalone "mock" (from PyPI) instead of builtin "unittest.mock" '
307-
'on Python 3',
308-
default=False)
297+
parser.addini(
298+
"mock_traceback_monkeypatch",
299+
"Monkeypatch the mock library to improve reporting of the "
300+
"assert_called_... methods",
301+
default=True,
302+
)
303+
parser.addini(
304+
"mock_use_standalone_module",
305+
'Use standalone "mock" (from PyPI) instead of builtin "unittest.mock" '
306+
"on Python 3",
307+
default=False,
308+
)
309309

310310

311311
def parse_ini_boolean(value):
312312
if value in (True, False):
313313
return value
314314
try:
315-
return {'true': True, 'false': False}[value.lower()]
315+
return {"true": True, "false": False}[value.lower()]
316316
except KeyError:
317-
raise ValueError('unknown string for bool: %r' % value)
317+
raise ValueError("unknown string for bool: %r" % value)
318318

319319

320320
def pytest_configure(config):
321-
tb = config.getoption('--tb')
322-
if parse_ini_boolean(config.getini('mock_traceback_monkeypatch')) and tb != 'native':
321+
tb = config.getoption("--tb")
322+
if (
323+
parse_ini_boolean(config.getini("mock_traceback_monkeypatch"))
324+
and tb != "native"
325+
):
323326
wrap_assert_methods(config)

setup.py

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,35 @@
33
from setuptools import setup
44

55
setup(
6-
name='pytest-mock',
7-
entry_points={
8-
'pytest11': ['pytest_mock = pytest_mock'],
9-
},
10-
py_modules=['pytest_mock', '_pytest_mock_version'],
11-
platforms='any',
12-
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
13-
install_requires=[
14-
'pytest>=2.7',
15-
'mock;python_version<"3.0"',
16-
],
17-
use_scm_version={'write_to': '_pytest_mock_version.py'},
18-
setup_requires=['setuptools_scm'],
19-
url='https://github.com/pytest-dev/pytest-mock/',
20-
license='MIT',
21-
author='Bruno Oliveira',
22-
author_email='[email protected]',
23-
description='Thin-wrapper around the mock package for easier use with py.test',
24-
long_description=open('README.rst', encoding='utf-8').read(),
6+
name="pytest-mock",
7+
entry_points={"pytest11": ["pytest_mock = pytest_mock"]},
8+
py_modules=["pytest_mock", "_pytest_mock_version"],
9+
platforms="any",
10+
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
11+
install_requires=["pytest>=2.7", 'mock;python_version<"3.0"'],
12+
use_scm_version={"write_to": "_pytest_mock_version.py"},
13+
setup_requires=["setuptools_scm"],
14+
url="https://github.com/pytest-dev/pytest-mock/",
15+
license="MIT",
16+
author="Bruno Oliveira",
17+
author_email="[email protected]",
18+
description="Thin-wrapper around the mock package for easier use with py.test",
19+
long_description=open("README.rst", encoding="utf-8").read(),
2520
keywords="pytest mock",
26-
extras_require={
27-
"dev": [
28-
"pre-commit",
29-
"tox",
30-
]
31-
},
21+
extras_require={"dev": ["pre-commit", "tox"]},
3222
classifiers=[
33-
'Development Status :: 5 - Production/Stable',
34-
'Framework :: Pytest',
35-
'Intended Audience :: Developers',
36-
'License :: OSI Approved :: MIT License',
37-
'Operating System :: OS Independent',
38-
'Programming Language :: Python :: 2',
39-
'Programming Language :: Python :: 2.7',
40-
'Programming Language :: Python :: 3',
41-
'Programming Language :: Python :: 3.4',
42-
'Programming Language :: Python :: 3.5',
43-
'Programming Language :: Python :: 3.6',
44-
'Programming Language :: Python :: 3.7',
45-
'Topic :: Software Development :: Testing',
46-
]
23+
"Development Status :: 5 - Production/Stable",
24+
"Framework :: Pytest",
25+
"Intended Audience :: Developers",
26+
"License :: OSI Approved :: MIT License",
27+
"Operating System :: OS Independent",
28+
"Programming Language :: Python :: 2",
29+
"Programming Language :: Python :: 2.7",
30+
"Programming Language :: Python :: 3",
31+
"Programming Language :: Python :: 3.4",
32+
"Programming Language :: Python :: 3.5",
33+
"Programming Language :: Python :: 3.6",
34+
"Programming Language :: Python :: 3.7",
35+
"Topic :: Software Development :: Testing",
36+
],
4737
)

0 commit comments

Comments
 (0)