[Python-checkins] cpython: Closes #21270 : We now override tuple methods in mock.call objects.

kushal.das python-checkins at python.org
Tue Sep 16 15:04:03 CEST 2014


http://hg.python.org/cpython/rev/5660c1bdc2b6
changeset:   92437:5660c1bdc2b6
user:        Kushal Das <kushaldas at gmail.com>
date:        Tue Sep 16 18:33:37 2014 +0530
summary:
  Closes #21270 : We now override tuple methods in mock.call objects.

files:
  Lib/unittest/mock.py                   |   6 ++++++
  Lib/unittest/test/testmock/testmock.py |  10 ++++++++++
  Misc/NEWS                              |   3 +++
  3 files changed, 19 insertions(+), 0 deletions(-)


diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2035,6 +2035,12 @@
         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'
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -1213,6 +1213,16 @@
         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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -157,6 +157,9 @@
 - 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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list