diff options
author | Xtreak <tirkarthi@users.noreply.github.com> | 2018-12-12 13:24:54 +0530 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2019-04-30 08:39:55 +0100 |
commit | a7b0ba10a004d3252b9f83684eb5aca1174efb07 (patch) | |
tree | 75f04e33642ff818f6524fc13deedd875d3e3326 /mock/tests/testhelpers.py | |
parent | 796edd45b3eab4dc8b9fe17c528bc51f6a613b67 (diff) | |
download | mock-a7b0ba10a004d3252b9f83684eb5aca1174efb07.tar.gz |
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
Backports: f7fa62ef4422c9deee050a794fd8504640d9f8f4
Signed-off-by: Chris Withers <chris@withers.org>
Diffstat (limited to 'mock/tests/testhelpers.py')
-rw-r--r-- | mock/tests/testhelpers.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mock/tests/testhelpers.py b/mock/tests/testhelpers.py index a0c61bf..2734f86 100644 --- a/mock/tests/testhelpers.py +++ b/mock/tests/testhelpers.py @@ -3,6 +3,7 @@ # http://www.voidspace.org.uk/python/mock/ import socket +import inspect import six import sys import time @@ -990,6 +991,35 @@ class SpecSignatureTest(unittest.TestCase): self.assertFalse(hasattr(autospec, '__name__')) + def test_spec_inspect_signature(self): + + def myfunc(x, y): + pass + + mock = create_autospec(myfunc) + mock(1, 2) + mock(x=1, y=2) + + self.assertEqual(inspect.getfullargspec(mock), inspect.getfullargspec(myfunc)) + self.assertEqual(mock.mock_calls, [call(1, 2), call(x=1, y=2)]) + self.assertRaises(TypeError, mock, 1) + + + def test_spec_inspect_signature_annotations(self): + + def foo(a: int, b: int=10, *, c:int) -> int: + return a + b + c + + mock = create_autospec(foo) + mock(1, 2, c=3) + mock(1, c=3) + + self.assertEqual(inspect.getfullargspec(mock), inspect.getfullargspec(foo)) + self.assertEqual(mock.mock_calls, [call(1, 2, c=3), call(1, c=3)]) + self.assertRaises(TypeError, mock, 1) + self.assertRaises(TypeError, mock, 1, 2, 3, c=4) + + class TestCallList(unittest.TestCase): def test_args_list_contains_call_list(self): |