diff options
author | Michael Foord <michael@voidspace.org.uk> | 2012-11-05 21:38:05 +0000 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2012-11-05 21:38:05 +0000 |
commit | f7c6e2d5362534dccc6a3dd91daa7cf053cd79be (patch) | |
tree | 1d44e4def3c2fa46419d9394db4e493261abfcfa | |
parent | 1a63f1dc06d1d334e00dbd9e1373d78edb032f2f (diff) | |
download | mock-f7c6e2d5362534dccc6a3dd91daa7cf053cd79be.tar.gz |
Add __wrapped__ to functions decorated with patch variants
-rw-r--r-- | README.txt | 4 | ||||
-rw-r--r-- | docs/changelog.txt | 12 | ||||
-rw-r--r-- | mock.py | 15 | ||||
-rwxr-xr-x | setup.py | 1 | ||||
-rw-r--r-- | tests/testpatch.py | 19 | ||||
-rw-r--r-- | tox.ini | 2 |
6 files changed, 47 insertions, 6 deletions
@@ -18,8 +18,8 @@ with the latest versions of Jython and pypy. The mock module also provides utility functions / objects to assist with testing, particularly monkey patching. -* `PDF documentation for 1.0 - <http://www.voidspace.org.uk/downloads/mock-1.0.0.pdf>`_ +* `PDF documentation for 1.0.1 + <http://www.voidspace.org.uk/downloads/mock-1.0.1.pdf>`_ * `mock on google code (repository and issue tracker) <http://code.google.com/p/mock/>`_ * `mock documentation diff --git a/docs/changelog.txt b/docs/changelog.txt index a605be3..77a84a4 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -4,6 +4,18 @@ CHANGELOG ========= +2012/11/5 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 ------------------------ @@ -30,7 +30,7 @@ __all__ = ( ) -__version__ = '1.0.0' +__version__ = '1.0.1' import pprint @@ -44,7 +44,7 @@ except ImportError: inspect = None try: - from functools import wraps + from functools import wraps as original_wraps except ImportError: # Python 2.4 compatibility def wraps(original): @@ -52,8 +52,19 @@ except ImportError: f.__name__ = original.__name__ f.__doc__ = original.__doc__ f.__module__ = original.__module__ + f.__wrapped__ = original return f return inner +else: + if sys.version_info[:2] >= (3, 3): + wraps = original_wraps + else: + def wraps(func): + def inner(f): + f = original_wraps(func)(f) + f.__wrapped__ = func + return f + return inner try: unicode @@ -26,7 +26,6 @@ CLASSIFIERS = [ 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 2.4', 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', diff --git a/tests/testpatch.py b/tests/testpatch.py index 1ebe671..2c13b49 100644 --- a/tests/testpatch.py +++ b/tests/testpatch.py @@ -1785,6 +1785,25 @@ class PatchTest(unittest2.TestCase): self.assertIs(os.path, path) + def test_wrapped_patch(self): + decorated = patch('sys.modules')(function) + self.assertIs(decorated.__wrapped__, function) + + + def test_wrapped_patch_object(self): + decorated = patch.object(sys, 'modules')(function) + self.assertIs(decorated.__wrapped__, function) + + + def test_wrapped_patch_dict(self): + decorated = patch.dict('sys.modules')(function) + self.assertIs(decorated.__wrapped__, function) + + + def test_wrapped_patch_multiple(self): + decorated = patch.multiple('sys', modules={})(function) + self.assertIs(decorated.__wrapped__, function) + if __name__ == '__main__': unittest2.main() @@ -1,5 +1,5 @@ [tox] -envlist = py24,py25,py26,py27,py31,pypy,py32,py33,jython +envlist = py25,py26,py27,py31,pypy,py32,py33,jython [testenv] deps=unittest2 |