diff options
author | Xtreak <tirkarthi@users.noreply.github.com> | 2018-12-12 07:54:54 (GMT) |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2018-12-12 07:54:54 (GMT) |
commit | f7fa62ef4422c9deee050a794fd8504640d9f8f4 (patch) | |
tree | 1a55b52b7e7d8122b3ee33f4d18c2adf018c63ea /Lib/unittest/mock.py | |
parent | 5344501ad166c1380be452644a863a4679c4291b (diff) | |
download | cpython-f7fa62ef4422c9deee050a794fd8504640d9f8f4.zip cpython-f7fa62ef4422c9deee050a794fd8504640d9f8f4.tar.gz cpython-f7fa62ef4422c9deee050a794fd8504640d9f8f4.tar.bz2 |
bpo-17185: Add __signature__ to mock that can be used by inspect for signature (GH11048)
* Fix partial and partial method signatures in mock
* Add more calls
* Add NEWS entry
* Use assertEquals and fix markup in NEWS
* Refactor branching and add markup reference for functools
* Revert partial object related changes and fix pr comments
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 61ed80b..38189c9 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -103,6 +103,7 @@ def _check_signature(func, mock, skipfirst, instance=False): sig.bind(*args, **kwargs) _copy_func_details(func, checksig) type(mock)._mock_check_sig = checksig + type(mock).__signature__ = sig def _copy_func_details(func, funcopy): @@ -172,11 +173,11 @@ def _set_signature(mock, original, instance=False): return mock(*args, **kwargs)""" % name exec (src, context) funcopy = context[name] - _setup_func(funcopy, mock) + _setup_func(funcopy, mock, sig) return funcopy -def _setup_func(funcopy, mock): +def _setup_func(funcopy, mock, sig): funcopy.mock = mock # can't use isinstance with mocks @@ -224,6 +225,7 @@ def _setup_func(funcopy, mock): funcopy.assert_called = assert_called funcopy.assert_not_called = assert_not_called funcopy.assert_called_once = assert_called_once + funcopy.__signature__ = sig mock._mock_delegate = funcopy |