[issue21269] Provide args and kwargs attributes on mock call objects

2019-04-02 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks @kakshay for the patch.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-03-22 Thread Chris Withers


Chris Withers  added the comment:


New changeset b0df45e55dc8304bac0e3cad0225472b84190964 by Chris Withers (Kumar 
Akshay) in branch 'master':
bpo-21269: Provide args and kwargs attributes on mock call objects GH11807
https://github.com/python/cpython/commit/b0df45e55dc8304bac0e3cad0225472b84190964


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-03-16 Thread Kumar Akshay

Kumar Akshay  added the comment:

ping..

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

This feels safer to me with respect to backwards compatibility and also that it 
might be easier to backport this to mock on GitHub which works with Python 2.7. 
I have less knowledge on difference between tuple and namedtuple internals so I 
might be wrong here.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

@xtreak, couldn't we have made `_Call` inherit from namedtuple to achieve a 
similar result (albeit the handling of name would be weird)?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

I like this patch, working with calls often feels weird and this change 
simplify attribute access.

--
nosy: +remi.lapeyre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Kumar Akshay

Kumar Akshay  added the comment:

Thanks @xtreak!
I've added a PR with the following API

➜  cpython git:(fix-issue-21269) ✗ ./python.exe
Python 3.8.0a0 (heads/fix-issue-21269-dirty:2433a2ab70, Feb 10 2019, 14:24:54)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from unittest.mock import Mock
>>> m = Mock()
>>> m(1, a=23)

>>> m.call_args
call(1, a=23)
>>> m.call_args.args #after this patch
(1,)
>>> m.call_args.kwargs   #after this patch
{'a': 23}
>>> m.call_args_list[0].args#after this patch
(1,)
>>> m.call_args_list[0].kwargs   #after this patch
{'a': 23}

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Kumar Akshay


Change by Kumar Akshay :


--
keywords: +patch, patch, patch
pull_requests: +11819, 11820, 11821
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Kumar Akshay


Change by Kumar Akshay :


--
keywords: +patch
pull_requests: +11819
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Kumar Akshay


Change by Kumar Akshay :


--
keywords: +patch, patch
pull_requests: +11819, 11820
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-09 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

@kakshay, I am not working on it so feel free to pick it up. I stumbled upon 
this while looking into mock issues and I just posted a patch to gather API 
feedback. I guess it would be helpful if someone confirms it would be a good 
addition so that there is less rework.

Thanks

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-09 Thread Kumar Akshay


Kumar Akshay  added the comment:

Hey @xtreak, if you're not working on this, can I submit the patch?

--
nosy: +kakshay

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-09 Thread Karthikeyan Singaravelan

Karthikeyan Singaravelan  added the comment:

args and kwargs property can be introduced on the call object to return the 
args and kwargs stored in the tuple. Currently wrapping call object with tuple 
can get a tuple of args and kwargs but a property would be helpful. A first 
attempt patch on this. Feedback on the API would be helpful.

$ ./python.exe
Python 3.8.0a1+ (heads/master:8a03ff2ff4, Feb  9 2019, 10:42:29)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from unittest.mock import Mock
>>> m = Mock()
>>> m(1, a=1)

>>> m.call_args_list[0]
call(1, a=1)
>>> tuple(m.call_args_list[0]) # wrapping it with tuple can give args and 
>>> kwargs currently
((1,), {'a': 1})
>>> m.call_args_list[0].args # With patch return args
(1,)
>>> m.call_args_list[0].kwargs # With patch return kwargs
{'a': 1}

A simple patch would be as below : 

➜  cpython git:(master) ✗ git diff | cat
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index ef5c55d6a1..ef1aa1dcea 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2124,6 +2124,24 @@ class _Call(tuple):
 def index(self, *args, **kwargs):
 return self.__getattr__('index')(*args, **kwargs)

+@property
+def args(self):
+if len(self) == 2:
+args, kwargs = self
+else:
+name, args, kwargs = self
+
+return args
+
+@property
+def kwargs(self):
+if len(self) == 2:
+args, kwargs = self
+else:
+name, args, kwargs = self
+
+return kwargs
+
 def __repr__(self):
 if not self._mock_from_kall:
 name = self._mock_name or 'call'

--
nosy: +cjw296, xtreak
versions: +Python 3.8 -Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2014-04-16 Thread Michael Foord

New submission from Michael Foord:

The unittest.mock.call object could have args/kwargs attributes to easily 
access the arguments it was called with.

--
messages: 216585
nosy: michael.foord
priority: normal
severity: normal
status: open
title: Provide args and kwargs attributes on mock call objects

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21269
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21269] Provide args and kwargs attributes on mock call objects

2014-04-16 Thread Michael Foord

Changes by Michael Foord mich...@voidspace.org.uk:


--
assignee:  - michael.foord
components: +Library (Lib)
nosy: +kushal.das
stage:  - needs patch
type:  - behavior
versions: +Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21269
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com