Skip to content

Commit

Permalink
Closes python#21270 : We now override tuple methods in mock.call obje…
Browse files Browse the repository at this point in the history
…cts.
  • Loading branch information
kushaldas committed Sep 16, 2014
1 parent a0f3375 commit a37b958
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,12 @@ def __getattr__(self, attr):
return _Call(name=name, parent=self, from_kall=False)


def count(self, *args, **kwargs):
return self.__getattr__('count')(*args, **kwargs)

def index(self, *args, **kwargs):
return self.__getattr__('index')(*args, **kwargs)

def __repr__(self):
if not self.from_kall:
name = self.name or 'call'
Expand Down
10 changes: 10 additions & 0 deletions Lib/unittest/test/testmock/testmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,16 @@ def test_sorted_call_signature(self):
text = "call(daddy='hero', name='hello')"
self.assertEqual(repr(m.hello.call_args), text)

#Issue21270 overrides tuple methods for mock.call objects
def test_override_tuple_methods(self):
c = call.count()
i = call.index(132,'hello')
m = Mock()
m.count()
m.index(132,"hello")
self.assertEqual(m.method_calls[0], c)
self.assertEqual(m.method_calls[1], i)

def test_mock_add_spec(self):
class _One(object):
one = 1
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ Library
- Issue #12410: imaplib.IMAP4 now supports the context management protocol.
Original patch by Tarek Ziadé.

- Issue #21270: We now override tuple methods in mock.call objects so that
they can be used as normal call attributes.

- Issue #16662: load_tests() is now unconditionally run when it is present in
a package's __init__.py. TestLoader.loadTestsFromModule() still accepts
use_load_tests, but it is deprecated and ignored. A new keyword-only
Expand Down

0 comments on commit a37b958

Please sign in to comment.