aboutsummaryrefslogtreecommitdiffstats
path: root/test/mock.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/mock.py')
-rw-r--r--test/mock.py55
1 files changed, 22 insertions, 33 deletions
diff --git a/test/mock.py b/test/mock.py
index c31bdf2..46af0d5 100644
--- a/test/mock.py
+++ b/test/mock.py
@@ -12,9 +12,6 @@
# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
# Comments, suggestions and bug reports welcome.
-import pprint
-import sys
-
__all__ = (
'Mock',
'MagicMock',
@@ -31,8 +28,8 @@ __all__ = (
'PropertyMock',
)
-
-__version__ = '1.1'
+import pprint
+import sys
try:
import inspect
@@ -272,7 +269,7 @@ def _set_signature(mock, original, instance=False):
src = """def %s(*args, **kwargs):
_checksig_(*args, **kwargs)
return mock(*args, **kwargs)""" % name
- exec (src, context)
+ exec(src, context)
funcopy = context[name]
_setup_func(funcopy, mock)
return funcopy
@@ -470,7 +467,8 @@ class NonCallableMock(Base):
def __init__(
self, spec=None, wraps=None, name=None, spec_set=None,
parent=None, _spec_state=None, _new_name='', _new_parent=None,
- **kwargs):
+ **kwargs
+ ):
if _new_parent is None:
_new_parent = parent
@@ -748,10 +746,7 @@ class NonCallableMock(Base):
if not _is_instance_mock(value):
setattr(type(self), name, _get_method(name, value))
original = value
-
- def value(*args, **kw):
- return original(self, *arg, **kw)
- # value = lambda *args, **kw: original(self, *args, **kw)
+ original = lambda *args, **kw: original(self, *args, **kw)
else:
# only set _new_name and not name so that mock_calls is tracked
# but not method calls
@@ -1003,8 +998,8 @@ class Mock(CallableMixin, NonCallableMock):
* `spec`: This can be either a list of strings or an existing object (a
class or instance) that acts as the specification for the mock object. If
you pass in an object then a list of strings is formed by calling dir on
- the object (excluding unsupported magic attributes and methods). Accessing
- any attribute not in this list will raise an `AttributeError`.
+ the object (excluding unsupported magic attributes and methods).
+ Accessing any attribute not in this list will raise an `AttributeError`.
If `spec` is an object (rather than a list of strings) then
`mock.__class__` returns the class of the spec object. This allows mocks
@@ -1081,7 +1076,8 @@ class _patch(object):
def __init__(
self, getter, attribute, new, spec, create,
- spec_set, autospec, new_callable, kwargs):
+ spec_set, autospec, new_callable, kwargs
+ ):
if new_callable is not None:
if new is not DEFAULT:
raise ValueError(
@@ -1366,17 +1362,15 @@ def _get_target(target):
except (TypeError, ValueError):
raise TypeError("Need a valid target to patch. You supplied: %r" %
(target,))
-
- def getter():
- return _importer(target)
- # getter = lambda: _importer(target)
+ getter = lambda: _importer(target)
return getter, attribute
def _patch_object(
target, attribute, new=DEFAULT, spec=None,
create=False, spec_set=None, autospec=None,
- new_callable=None, **kwargs):
+ new_callable=None, **kwargs
+ ):
"""
patch.object(target, attribute, new=DEFAULT, spec=None, create=False,
spec_set=None, autospec=None, new_callable=None, **kwargs)
@@ -1393,10 +1387,7 @@ def _patch_object(
When used as a class decorator `patch.object` honours `patch.TEST_PREFIX`
for choosing which methods to wrap.
"""
-
- def getter():
- return target
- # getter = lambda: target
+ getter = lambda: target
return _patch(
getter, attribute, new, spec, create,
spec_set, autospec, new_callable, kwargs
@@ -1426,15 +1417,9 @@ def _patch_multiple(target, spec=None, create=False, spec_set=None,
for choosing which methods to wrap.
"""
if type(target) in (unicode, str):
-
- def getter():
- return _importer(target)
- # getter = lambda: _importer(target)
+ getter = lambda: _importer(target)
else:
-
- def getter():
- return target
- # getter = lambda: target
+ getter = lambda: target
if not kwargs:
raise ValueError(
@@ -1460,7 +1445,8 @@ def _patch_multiple(target, spec=None, create=False, spec_set=None,
def patch(
target, new=DEFAULT, spec=None, create=False,
- spec_set=None, autospec=None, new_callable=None, **kwargs):
+ spec_set=None, autospec=None, new_callable=None, **kwargs
+ ):
"""
`patch` acts as a function decorator, class decorator or a context
manager. Inside the body of the function or with statement, the `target`
@@ -1776,6 +1762,7 @@ def _get_iter(self):
return iter(ret_val)
return __iter__
+
_side_effect_methods = {
'__eq__': _get_eq,
'__ne__': _get_ne,
@@ -1899,6 +1886,7 @@ class _ANY(object):
def __repr__(self):
return '<ANY>'
+
ANY = _ANY()
@@ -2278,7 +2266,8 @@ def mock_open(mock=None, read_data=''):
# set on first use
if inPy3k:
import _io
- file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
+ file_spec = list(set(dir(
+ _io.TextIOWrapper)).union(set(dir(_io.BytesIO))))
else:
file_spec = file