diff options
author | Lisa Roach <lisaroach14@gmail.com> | 2019-09-19 21:04:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-19 21:04:18 -0700 |
commit | 8b03f943c37e07fb2394acdcfacd066647f9b1fd (patch) | |
tree | c1e3951fe13dc337f99b78bd3521867dd19c2ac6 /Lib/unittest/test/testmock/testmagicmethods.py | |
parent | 2702638eabe5f7b25f36d295f0ad78cb8d4eda05 (diff) | |
download | cpython-8b03f943c37e07fb2394acdcfacd066647f9b1fd.tar.gz cpython-8b03f943c37e07fb2394acdcfacd066647f9b1fd.zip |
bpo-38093: Correctly returns AsyncMock for async subclasses. (GH-15947)
Diffstat (limited to 'Lib/unittest/test/testmock/testmagicmethods.py')
-rw-r--r-- | Lib/unittest/test/testmock/testmagicmethods.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py index 130a3397ba0..57f85e951e2 100644 --- a/Lib/unittest/test/testmock/testmagicmethods.py +++ b/Lib/unittest/test/testmock/testmagicmethods.py @@ -1,8 +1,9 @@ +import asyncio import math import unittest import os import sys -from unittest.mock import Mock, MagicMock, _magics +from unittest.mock import AsyncMock, Mock, MagicMock, _magics @@ -271,6 +272,34 @@ class TestMockingMagicMethods(unittest.TestCase): self.assertEqual(mock != mock, False) + # This should be fixed with issue38163 + @unittest.expectedFailure + def test_asyncmock_defaults(self): + mock = AsyncMock() + self.assertEqual(int(mock), 1) + self.assertEqual(complex(mock), 1j) + self.assertEqual(float(mock), 1.0) + self.assertNotIn(object(), mock) + self.assertEqual(len(mock), 0) + self.assertEqual(list(mock), []) + self.assertEqual(hash(mock), object.__hash__(mock)) + self.assertEqual(str(mock), object.__str__(mock)) + self.assertTrue(bool(mock)) + self.assertEqual(round(mock), mock.__round__()) + self.assertEqual(math.trunc(mock), mock.__trunc__()) + self.assertEqual(math.floor(mock), mock.__floor__()) + self.assertEqual(math.ceil(mock), mock.__ceil__()) + self.assertTrue(asyncio.iscoroutinefunction(mock.__aexit__)) + self.assertTrue(asyncio.iscoroutinefunction(mock.__aenter__)) + self.assertIsInstance(mock.__aenter__, AsyncMock) + self.assertIsInstance(mock.__aexit__, AsyncMock) + + # in Python 3 oct and hex use __index__ + # so these tests are for __index__ in py3k + self.assertEqual(oct(mock), '0o1') + self.assertEqual(hex(mock), '0x1') + # how to test __sizeof__ ? + def test_magicmock_defaults(self): mock = MagicMock() self.assertEqual(int(mock), 1) @@ -286,6 +315,10 @@ class TestMockingMagicMethods(unittest.TestCase): self.assertEqual(math.trunc(mock), mock.__trunc__()) self.assertEqual(math.floor(mock), mock.__floor__()) self.assertEqual(math.ceil(mock), mock.__ceil__()) + self.assertTrue(asyncio.iscoroutinefunction(mock.__aexit__)) + self.assertTrue(asyncio.iscoroutinefunction(mock.__aenter__)) + self.assertIsInstance(mock.__aenter__, AsyncMock) + self.assertIsInstance(mock.__aexit__, AsyncMock) # in Python 3 oct and hex use __index__ # so these tests are for __index__ in py3k |