mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-96127: Fix inspect.signature
call on mocks (#96335)
This commit is contained in:
parent
a109454e82
commit
9e7d7266ec
3 changed files with 30 additions and 1 deletions
|
@ -3283,6 +3283,25 @@ class TestSignatureObject(unittest.TestCase):
|
|||
((('a', 10, ..., "positional_or_keyword"),),
|
||||
...))
|
||||
|
||||
def test_signature_on_mocks(self):
|
||||
# https://github.com/python/cpython/issues/96127
|
||||
for mock in (
|
||||
unittest.mock.Mock(),
|
||||
unittest.mock.AsyncMock(),
|
||||
unittest.mock.MagicMock(),
|
||||
):
|
||||
with self.subTest(mock=mock):
|
||||
self.assertEqual(str(inspect.signature(mock)), '(*args, **kwargs)')
|
||||
|
||||
def test_signature_on_noncallable_mocks(self):
|
||||
for mock in (
|
||||
unittest.mock.NonCallableMock(),
|
||||
unittest.mock.NonCallableMagicMock(),
|
||||
):
|
||||
with self.subTest(mock=mock):
|
||||
with self.assertRaises(TypeError):
|
||||
inspect.signature(mock)
|
||||
|
||||
def test_signature_equality(self):
|
||||
def foo(a, *, b:int) -> float: pass
|
||||
self.assertFalse(inspect.signature(foo) == 42)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue