diff options
author | blhsing <github@ydooby.com> | 2019-09-11 07:28:06 -0700 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2020-01-29 19:15:17 +0000 |
commit | a294948da73d1135e6ea955cb46413903a0906da (patch) | |
tree | 191c6bb27cd4350f9371303662401516ff08b394 /mock/tests/testhelpers.py | |
parent | 9b05bea15f383b90c155cff08032bb2db7fbae96 (diff) | |
download | mock-a294948da73d1135e6ea955cb46413903a0906da.tar.gz |
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__
Backports: 72c359912d36705a94fca8b63d80451905a14ae4
Signed-off-by: Chris Withers <chris@withers.org>
Diffstat (limited to 'mock/tests/testhelpers.py')
-rw-r--r-- | mock/tests/testhelpers.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/mock/tests/testhelpers.py b/mock/tests/testhelpers.py index 3dd95f2..eea9fe2 100644 --- a/mock/tests/testhelpers.py +++ b/mock/tests/testhelpers.py @@ -359,6 +359,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): |