mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable (GH-15565)
* bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable * 📜🤖 Added by blurb_it. * Update 2019-08-28-21-40-12.bpo-37972.kP-n4L.rst added name of the contributor * bpo-37972: made all dunder methods chainable for _Call * bpo-37972: delegate only attributes of tuple instead to __getattr__
This commit is contained in:
parent
1abf54336f
commit
72c359912d
3 changed files with 31 additions and 0 deletions
|
@ -334,6 +334,26 @@ class CallTest(unittest.TestCase):
|
|||
self.assertEqual(_Call((('bar', 'barz'),),)[0], '')
|
||||
self.assertEqual(_Call((('bar', 'barz'), {'hello': 'world'}),)[0], '')
|
||||
|
||||
def test_dunder_call(self):
|
||||
m = MagicMock()
|
||||
m().foo()['bar']()
|
||||
self.assertEqual(
|
||||
m.mock_calls,
|
||||
[call(), call().foo(), call().foo().__getitem__('bar'), call().foo().__getitem__()()]
|
||||
)
|
||||
m = MagicMock()
|
||||
m().foo()['bar'] = 1
|
||||
self.assertEqual(
|
||||
m.mock_calls,
|
||||
[call(), call().foo(), call().foo().__setitem__('bar', 1)]
|
||||
)
|
||||
m = MagicMock()
|
||||
iter(m().foo())
|
||||
self.assertEqual(
|
||||
m.mock_calls,
|
||||
[call(), call().foo(), call().foo().__iter__()]
|
||||
)
|
||||
|
||||
|
||||
class SpecSignatureTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue