Issue37972
Created on 2019-08-28 20:33 by blhsing, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 15565 | merged | blhsing, 2019-08-28 21:17 | |
| PR 15965 | merged | miss-islington, 2019-09-11 14:28 | |
| Messages (8) | |||
|---|---|---|---|
| msg350688 - (view) | Author: Ben Hsing (blhsing) * | Date: 2019-08-28 20:33 | |
As reported on StackOverflow: https://stackoverflow.com/questions/57636747/how-to-perform-assert-has-calls-for-a-getitem-call The following code would output: [call(), call().foo(), call().foo().__getitem__('bar')] from unittest.mock import MagicMock, call mm = MagicMock() mm().foo()['bar'] print(mm.mock_calls) but trying to use that list with mm.assert_has_calls([call(), call().foo(), call().foo().__getitem__('bar')]) would result in: TypeError: tuple indices must be integers or slices, not str |
|||
| msg351830 - (view) | Author: Karthikeyan Singaravelan (xtreak) * | Date: 2019-09-11 11:34 | |
If we go ahead with this then we should also support other dunder methods of tuple like __setitem__ and so on. |
|||
| msg351846 - (view) | Author: Ben Hsing (blhsing) * | Date: 2019-09-11 12:45 | |
Agreed. I've submitted a new commit with the call chaining behavior now generalized for all dunder methods by delegating the resolution of all attributes not directly in the _Call object's __dict__ keys to the getattr method. |
|||
| msg351877 - (view) | Author: Ben Hsing (blhsing) * | Date: 2019-09-11 13:42 | |
Correction. I've now done this by delegating the resolution of attributes belonging to the tuple class to _Call.__getattr__ instead. Passed all build tests. |
|||
| msg351903 - (view) | Author: Roundup Robot (python-dev) | Date: 2019-09-11 14:28 | |
New changeset 72c359912d36705a94fca8b63d80451905a14ae4 by Michael Foord (blhsing) in branch 'master': bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable (GH-15565) https://github.com/python/cpython/commit/72c359912d36705a94fca8b63d80451905a14ae4 |
|||
| msg352102 - (view) | Author: Roundup Robot (python-dev) | Date: 2019-09-12 10:52 | |
New changeset db0d8a5b2c803d30d9df436e00b6627ec8e09a13 by Michael Foord (Miss Islington (bot)) in branch '3.8': bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable (GH-15565) (GH-15965) https://github.com/python/cpython/commit/db0d8a5b2c803d30d9df436e00b6627ec8e09a13 |
|||
| msg354383 - (view) | Author: Karthikeyan Singaravelan (xtreak) * | Date: 2019-10-10 14:40 | |
Closing as fixed since PRs were merged. Thanks Ben. |
|||
| msg360973 - (view) | Author: Chris Withers (cjw296) * | Date: 2020-01-29 16:25 | |
New changeset db5e86adbce12350c26e7ffc2c6673369971a2dc by Chris Withers in branch 'master': Get mock coverage back to 100% (GH-18228) https://github.com/python/cpython/commit/db5e86adbce12350c26e7ffc2c6673369971a2dc |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:19 | admin | set | github: 82153 |
| 2020-01-29 16:25:00 | cjw296 | set | messages: + msg360973 |
| 2019-10-10 14:40:24 | xtreak | set | status: open -> closed resolution: fixed messages: + msg354383 stage: patch review -> resolved |
| 2019-09-12 10:52:52 | python-dev | set | messages: + msg352102 |
| 2019-09-11 14:28:20 | miss-islington | set | pull_requests: + pull_request15598 |
| 2019-09-11 14:28:09 | python-dev | set | nosy:
+ python-dev messages: + msg351903 |
| 2019-09-11 13:42:18 | blhsing | set | messages: + msg351877 |
| 2019-09-11 12:59:00 | blhsing | set | status: pending -> open |
| 2019-09-11 12:45:03 | blhsing | set | status: open -> pending messages: + msg351846 |
| 2019-09-11 11:34:48 | xtreak | set | nosy:
+ cjw296, michael.foord, mariocj89 messages:
+ msg351830 |
| 2019-08-28 21:17:21 | blhsing | set | keywords:
+ patch stage: patch review pull_requests: + pull_request15240 |
| 2019-08-28 20:58:09 | xtreak | set | nosy:
+ xtreak |
| 2019-08-28 20:33:01 | blhsing | create | |