mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
bpo-37251: Removes __code__ check from _is_async_obj. (GH-15830)
(cherry picked from commit f1a297acb6
)
Co-authored-by: Lisa Roach <lisaroach14@gmail.com>
This commit is contained in:
parent
eaa1b09412
commit
c3008dd480
3 changed files with 20 additions and 3 deletions
|
@ -18,6 +18,10 @@ class AsyncClass:
|
|||
def normal_method(self):
|
||||
pass
|
||||
|
||||
class AwaitableClass:
|
||||
def __await__(self):
|
||||
yield
|
||||
|
||||
async def async_func():
|
||||
pass
|
||||
|
||||
|
@ -160,6 +164,10 @@ class AsyncAutospecTest(unittest.TestCase):
|
|||
with self.assertRaises(RuntimeError):
|
||||
create_autospec(async_func, instance=True)
|
||||
|
||||
def test_create_autospec_awaitable_class(self):
|
||||
awaitable_mock = create_autospec(spec=AwaitableClass())
|
||||
self.assertIsInstance(create_autospec(awaitable_mock), AsyncMock)
|
||||
|
||||
def test_create_autospec(self):
|
||||
spec = create_autospec(async_func_args)
|
||||
awaitable = spec(1, 2, c=3)
|
||||
|
@ -321,6 +329,13 @@ class AsyncSpecSetTest(unittest.TestCase):
|
|||
self.assertIsInstance(mock.normal_method, MagicMock)
|
||||
self.assertIsInstance(mock, MagicMock)
|
||||
|
||||
def test_magicmock_lambda_spec(self):
|
||||
mock_obj = MagicMock()
|
||||
mock_obj.mock_func = MagicMock(spec=lambda x: x)
|
||||
|
||||
with patch.object(mock_obj, "mock_func") as cm:
|
||||
self.assertIsInstance(cm, MagicMock)
|
||||
|
||||
|
||||
class AsyncArguments(unittest.TestCase):
|
||||
def test_add_return_value(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue