diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-11-07 17:08:38 +0000 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-11-07 17:08:38 +0000 |
commit | 0818cd0411508ccf926f92f9164bc744aa5be849 (patch) | |
tree | 61897a582febc1ddc72591b48b0fa498f5c77e22 | |
parent | 37367061a7f93c59eac6e81b9ab6d2b30c8c03c5 (diff) | |
download | mock-0818cd0411508ccf926f92f9164bc744aa5be849.tar.gz |
Proper compatibility with functools.wraps
-rw-r--r-- | README.txt | 4 | ||||
-rw-r--r-- | docs/changelog.txt | 6 | ||||
-rw-r--r-- | mock.py | 10 | ||||
-rw-r--r-- | tests/testpatch.py | 6 |
4 files changed, 14 insertions, 12 deletions
@@ -171,7 +171,9 @@ the `__init__` method, and on callable objects where it copies the signature of the `__call__` method. The distribution contains tests and documentation. The tests require -`unittest2 <http://pypi.python.org/pypi/unittest2>`_ to run. +`unittest2 <http://pypi.python.org/pypi/unittest2>`_ to run on Python 2.5, 2.6 +or 3.1. For Python 2.7 and 3.2 they can be run with +`python -m unittest discover`. Docs from the in-development version of `mock` can be found at `mock.readthedocs.org <http://mock.readthedocs.org>`_. diff --git a/docs/changelog.txt b/docs/changelog.txt index 91a050d..3ae45d0 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -5,16 +5,12 @@ CHANGELOG ========= 2012/11/05 Version 1.0.1 ------------------------ +------------------------ * Functions decorated with `patch` variants have a `__wrapped__` attribute pointing to the original function. This brings compatibility with the default behaviour in Python 3.3 (due to a new feature in `functools.wraps`). -Note that due to changes in `tox`, `mock` is no longer tested with Python 2.4. -The compatibility code has not been removed so it probably still works, but -tests are no longer run. - 2012/10/07 Version 1.0.0 ------------------------ @@ -9,10 +9,6 @@ # Released subject to the BSD License # Please see http://www.voidspace.org.uk/python/license.shtml -# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml -# Comments, suggestions and bug reports welcome. - - __all__ = ( 'Mock', 'MagicMock', @@ -52,7 +48,8 @@ except ImportError: f.__name__ = original.__name__ f.__doc__ = original.__doc__ f.__module__ = original.__module__ - f.__wrapped__ = original + wrapped = getattr(original, '__wrapped__', original) + f.__wrapped__ = wrapped return f return inner else: @@ -62,7 +59,8 @@ else: def wraps(func): def inner(f): f = original_wraps(func)(f) - f.__wrapped__ = func + wrapped = getattr(func, '__wrapped__', func) + f.__wrapped__ = wrapped return f return inner diff --git a/tests/testpatch.py b/tests/testpatch.py index 2c13b49..8eb719b 100644 --- a/tests/testpatch.py +++ b/tests/testpatch.py @@ -1790,6 +1790,12 @@ class PatchTest(unittest2.TestCase): self.assertIs(decorated.__wrapped__, function) + def test_wrapped_several_times_patch(self): + decorated = patch('sys.modules')(function) + decorated = patch('sys.modules')(decorated) + self.assertIs(decorated.__wrapped__, function) + + def test_wrapped_patch_object(self): decorated = patch.object(sys, 'modules')(function) self.assertIs(decorated.__wrapped__, function) |