diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-01-07 10:49:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-07 10:49:15 (GMT) |
commit | 9e7d7266ecdcccc02385fe4ccb094f3444102e26 (patch) | |
tree | 99b6f78cf6e7b88ec03a4b437eb8e055a4758fe0 /Lib/test/test_inspect.py | |
parent | a109454e828ce2d9bde15dea78405f8ffee653ec (diff) | |
download | cpython-9e7d7266ecdcccc02385fe4ccb094f3444102e26.zip cpython-9e7d7266ecdcccc02385fe4ccb094f3444102e26.tar.gz cpython-9e7d7266ecdcccc02385fe4ccb094f3444102e26.tar.bz2 |
gh-96127: Fix `inspect.signature` call on mocks (#96335)
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 1b589c8..aa75724 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -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) |