Skip to content

Commit

Permalink
Calling spy() now fills args and kwargs with empty tuple or dictionary
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
jonathan-benn-copilot authored and note35 committed Sep 29, 2017
1 parent e0d11df commit d0fafaf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sinon/lib/spy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __remove_args_first_item(self):
if len(self.args) > 0:
new_args_list = []
for item in self.args:
if self.obj == item[0].__class__:
if len(item) > 0 and self.obj == item[0].__class__:
new_args_list.append(item[1:])
else:
new_args_list.append(item[:])
Expand Down
6 changes: 2 additions & 4 deletions sinon/lib/util/Wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ def wrapped(*args, **kwargs):
"""
wrapped.callCount += 1
CALLQUEUE.append(wrapped)
if args:
wrapped.args_list.append(args)
if kwargs:
wrapped.kwargs_list.append(kwargs)
wrapped.args_list.append(args)
wrapped.kwargs_list.append(kwargs)
try:
ret = func(*args, **kwargs)
wrapped.ret_list.append(ret)
Expand Down
16 changes: 16 additions & 0 deletions sinon/test/TestSinonSpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def D_func(err=False):
raise err
else:
return "test_local_D_func"

def E_func(*args, **kwargs):
return str(args) + ' ' + str(kwargs)

"""
======================================================
FOR TEST ONLY END
Expand Down Expand Up @@ -852,3 +856,15 @@ def test240_neverCalledWithMatch_args(self):
self.assertTrue(spy.neverCalledWithMatch("a", "e"))
self.assertTrue(spy.neverCalledWithMatch("d", "e", "c")) #it's a combination

@sinontest
def test270_args_and_kwargs(self):
spy = SinonSpy(E_func)
sinon.g.E_func()
self.assertListEqual(spy.args, [()])
self.assertListEqual(spy.kwargs, [{}])
sinon.g.E_func(1, a=1)
self.assertListEqual(spy.args, [(), (1,)])
self.assertListEqual(spy.kwargs, [{}, {'a':1}])
sinon.g.E_func(1, 2, a=1, b=2)
self.assertListEqual(spy.args, [(), (1,), (1,2)])
self.assertListEqual(spy.kwargs, [{}, {'a':1}, {'a':1,'b':2}])

0 comments on commit d0fafaf

Please sign in to comment.