summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/testmock/testhelpers.py
diff options
context:
space:
mode:
authorXtreak <tirkarthi@users.noreply.github.com>2018-12-12 07:54:54 (GMT)
committerChris Withers <chris@withers.org>2018-12-12 07:54:54 (GMT)
commitf7fa62ef4422c9deee050a794fd8504640d9f8f4 (patch)
tree1a55b52b7e7d8122b3ee33f4d18c2adf018c63ea /Lib/unittest/test/testmock/testhelpers.py
parent5344501ad166c1380be452644a863a4679c4291b (diff)
downloadcpython-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/test/testmock/testhelpers.py')
-rw-r--r--Lib/unittest/test/testmock/testhelpers.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py
index 9388311..745580e 100644
--- a/Lib/unittest/test/testmock/testhelpers.py
+++ b/Lib/unittest/test/testmock/testhelpers.py
@@ -1,3 +1,4 @@
+import inspect
import time
import types
import unittest
@@ -901,6 +902,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):