Issue 28961: unittest.mock._Call ignores name parameter (original) (raw)

Created on 2016-12-13 13:47 by Jiajun Huang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mock_class_call.patch Jiajun Huang,2016-12-14 02:15 review
mock.patch Jiajun Huang,2016-12-14 02:41 review
mock.patch Jiajun Huang,2016-12-14 05:46 review
mock.patch Jiajun Huang,2016-12-16 07:12 review
mock.patch Jiajun Huang,2017-01-03 14:34 review
Pull Requests
URL Status Linked Edit
PR 305 merged berker.peksag,2017-02-26 11:39
PR 306 merged berker.peksag,2017-02-26 11:42
PR 552 closed dstufft,2017-03-31 16:36
Messages (19)
msg283104 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2016-12-13 13:47
code in `_Call.__new__`: def __new__(cls, value=(), name=None, parent=None, two=False, ¦ ¦ ¦ from_kall=True): ¦ name = '' ¦ args = () ¦ kwargs = {} ¦ _len = len(value) ¦ if _len == 3: ... the parameter `name` had been override since the function starts. so whatever name is, it's been ignored. Is it a bug? or something else?
msg283120 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2016-12-13 16:38
That indeed looks like a bug. Well spotted :) That code has been there since unittest.mock was added back in March 2012. If I were to guess, I'd say that it should be `if name is None: name = ''`. Care to submit a patch?
msg283157 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2016-12-14 02:15
Thanks for reply :) the patch has been uploaded.
msg283159 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2016-12-14 02:41
update the patch file follow the doc(https://docs.python.org/devguide/gitdevs.html)
msg283164 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2016-12-14 05:46
The new patch has been updated. :)
msg283231 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-12-15 02:46
Thanks for the patch, Jiajun. The _Call class is tested in CallTest (located in Lib/unittest/test/testmock/testhelpers.py) Would it be possible to add a test case to make sure that we actually fixed the bug?
msg283235 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2016-12-15 03:40
I think we can write `_Call.__new__` as: def __new__(cls, value=(), name='',...) it's much simpler and readable.
msg283369 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2016-12-16 07:12
code and test case has been updated.
msg284246 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2016-12-29 10:44
hi, do this need more test case or something else to be merged? please let me know :)
msg284564 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-03 14:09
Please remove "import ipdb; ipdb.set_trace() # TODO remove it" before posting patches ;-)
msg284572 - (view) Author: Jiajun Huang (Jiajun Huang) * Date: 2017-01-03 14:34
sorry about that, fixed.
msg284589 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-01-03 19:25
The patch looks good to me. There are some styling issues in the test code (e.g. no need to add trailing spaces after commas in some cases), but I can take care of them before committing the patch :) Thanks!
msg284595 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-03 22:12
The latest patch (Jiajun Huang, 2017-01-03 14:34) LGTM.
msg284823 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2017-01-06 14:59
Yep, LGTM as well. Nicely spotted!
msg284839 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-06 17:16
New changeset 50424a903593 by Victor Stinner in branch '3.6': Fix unittest.mock._Call: don't ignore name https://hg.python.org/cpython/rev/50424a903593
msg284840 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-06 17:18
I applied the latest mock.patch to Python 3.6 and default (future 3.7). I prefer to wait for the 3.5.3 release before backporting the fix to 3.5, the fix is minor, I don't want to annoy the release manager yet.
msg284885 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-01-07 05:04
IIRC 3.5.3rc1 is already tagged so the 3.5 branch is open for 3.5.4. Anything that needs to be in 3.5.3 should be cherry-picked by the RM at this point if I'm not mistaken (and note that I don't have time check, but 3.5.3 may be the last bugfix release of 3.5 series so you may just skip 3.5 :)) Like I already said in , the test code doesn't follow the current style in Lib/unittest/test/testmock/testhelpers.py and it can be simplified like the following patch: def test_call_with_name(self): - self.assertEqual( - 'foo', - _Call((), 'foo')[0], - ) - self.assertEqual( - '', - _Call((('bar', 'barz'), ), )[0] - ) - self.assertEqual( - '', - _Call((('bar', 'barz'), {'hello': 'world'}), )[0] - ) + self.assertEqual(_Call((), 'foo')[0], 'foo') + self.assertEqual(_Call((('bar', 'barz'),),)[0], '') + self.assertEqual(_Call((('bar', 'barz'), {'hello': 'world'}),)[0], '')
msg290393 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-03-24 23:42
New changeset fae59e1aa87ee9598d032e0bd697969a5784025f by Berker Peksag in branch '3.6': bpo-28961: Address my comments from earlier code review (#306) https://github.com/python/cpython/commit/fae59e1aa87ee9598d032e0bd697969a5784025f
msg290395 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-03-24 23:43
New changeset 5aa3856b4f325457e8ec1ccf669369f543e1f6b5 by Berker Peksag in branch 'master': bpo-28961: Address my comments from earlier code review (#305) https://github.com/python/cpython/commit/5aa3856b4f325457e8ec1ccf669369f543e1f6b5
History
Date User Action Args
2022-04-11 14:58:40 admin set github: 73147
2017-03-31 16:36:27 dstufft set pull_requests: + <pull%5Frequest1011>
2017-03-24 23:43:06 berker.peksag set messages: +
2017-03-24 23:42:40 berker.peksag set messages: +
2017-02-26 13:06:44 berker.peksag set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-02-26 11:42:13 berker.peksag set pull_requests: + <pull%5Frequest270>
2017-02-26 11:39:21 berker.peksag set pull_requests: + <pull%5Frequest269>
2017-01-07 05:04:12 berker.peksag set messages: +
2017-01-06 17🔞32 vstinner set messages: +
2017-01-06 17:16:32 python-dev set nosy: + python-devmessages: +
2017-01-06 14:59:50 michael.foord set messages: +
2017-01-03 22:12:24 vstinner set messages: +
2017-01-03 19:25:05 berker.peksag set messages: +
2017-01-03 14:34:54 Jiajun Huang set files: + mock.patchmessages: +
2017-01-03 14:09:41 vstinner set nosy: + vstinnermessages: +
2016-12-29 10:44:56 Jiajun Huang set messages: +
2016-12-16 07:12:06 Jiajun Huang set files: + mock.patchmessages: +
2016-12-15 03:40:52 Jiajun Huang set messages: +
2016-12-15 02:46:46 berker.peksag set nosy: + berker.peksagmessages: + stage: commit review -> patch review
2016-12-14 13:06:07 abarry set stage: needs patch -> commit review
2016-12-14 05:46:47 Jiajun Huang set files: + mock.patchmessages: +
2016-12-14 02:41:35 Jiajun Huang set files: + mock.patchmessages: +
2016-12-14 02:15:27 Jiajun Huang set files: + mock_class_call.patchkeywords: + patchmessages: +
2016-12-13 16:38:15 abarry set versions: + Python 3.5, Python 3.6type: enhancement -> behaviornosy: + abarry, michael.foordtitle: Is it a bug(method `_Call.__new__` in unittest.mock)? -> unittest.mock._Call ignores `name` parametermessages: + stage: needs patch
2016-12-13 13:47:48 Jiajun Huang create