diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-03-25 19:35:52 +0100 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-03-25 19:35:52 +0100 |
commit | 855baa2cc23014a100444f5b28cdf88452c23ab4 (patch) | |
tree | 7895aaeded946c25b110255226223436a670c33f | |
parent | b49cb7b38667e64696eff4833a46036f9f20ac5e (diff) | |
download | mock-855baa2cc23014a100444f5b28cdf88452c23ab4.tar.gz |
Minor cleanups
-rw-r--r-- | mock.py | 11 | ||||
-rw-r--r-- | tests/testpatch.py | 9 |
2 files changed, 7 insertions, 13 deletions
@@ -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): |