summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2012-03-25 19:35:52 +0100
committerMichael Foord <michael@voidspace.org.uk>2012-03-25 19:35:52 +0100
commit855baa2cc23014a100444f5b28cdf88452c23ab4 (patch)
tree7895aaeded946c25b110255226223436a670c33f
parentb49cb7b38667e64696eff4833a46036f9f20ac5e (diff)
downloadmock-855baa2cc23014a100444f5b28cdf88452c23ab4.tar.gz
Minor cleanups
-rw-r--r--mock.py11
-rw-r--r--tests/testpatch.py9
2 files changed, 7 insertions, 13 deletions
diff --git a/mock.py b/mock.py
index e852bcf..e3b2f39 100644
--- a/mock.py
+++ b/mock.py
@@ -1260,7 +1260,7 @@ class _patch(object):
_kwargs = {}
if new_callable is not None:
Klass = new_callable
- elif (spec or spec_set) is not None:
+ elif spec is not None or spec_set is not None:
if not _callable(spec or spec_set):
Klass = NonCallableMagicMock
@@ -1300,7 +1300,7 @@ class _patch(object):
"autospec and new."
)
if original is DEFAULT:
- raise TypeError("Can't use 'spec' with create=True")
+ raise TypeError("Can't use 'autospec' with create=True")
spec_set = bool(spec_set)
if autospec is True:
autospec = original
@@ -1394,8 +1394,7 @@ def _patch_object(
def _patch_multiple(target, spec=None, create=False, spec_set=None,
- autospec=None, new_callable=None, **kwargs
- ):
+ autospec=None, new_callable=None, **kwargs):
"""Perform multiple patches in a single call. It takes the object to be
patched (either as an object or a string to fetch the object by importing)
and keyword arguments for the patches::
@@ -2280,9 +2279,7 @@ def mock_open(mock=None, read_data=''):
handle = MagicMock(spec=file_spec)
handle.write.return_value = None
handle.__enter__.return_value = handle
-
- if read_data is not None:
- handle.read.return_value = read_data
+ handle.read.return_value = read_data
mock.return_value = handle
return mock
diff --git a/tests/testpatch.py b/tests/testpatch.py
index c9af333..443ad60 100644
--- a/tests/testpatch.py
+++ b/tests/testpatch.py
@@ -1691,12 +1691,9 @@ class PatchTest(unittest2.TestCase):
self.assertRaises(NameError, lambda: doesnotexist)
# check that spec with create is innocuous if the original exists
- p = patch(MODNAME, create=True,
- **{kwarg: True})
- try:
- p.start()
- finally:
- p.stop()
+ p = patch(MODNAME, create=True, **{kwarg: True})
+ p.start()
+ p.stop()
def test_multiple_specs(self):