]> granicus.if.org Git - python/commitdiff
Closes #21270 : We now override tuple methods in mock.call objects.
authorKushal Das <kushaldas@gmail.com>
Tue, 16 Sep 2014 13:03:37 +0000 (18:33 +0530)
committerKushal Das <kushaldas@gmail.com>
Tue, 16 Sep 2014 13:03:37 +0000 (18:33 +0530)
Lib/unittest/mock.py
Lib/unittest/test/testmock/testmock.py
Misc/NEWS

index d00197688ae0f04b1111bac6f8315942ae9b3931..1c2dd1c1e204abef3b610274e85d4878859d378e 100644 (file)
@@ -2035,6 +2035,12 @@ class _Call(tuple):
         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'
index a5499732c22a526c295aab55e027f4166ea31a5c..3a104cb2b9d6455a1495b3dca4b4a7dece94113c 100644 (file)
@@ -1213,6 +1213,16 @@ class MockTest(unittest.TestCase):
         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
index d9bac606240c7cc6373f19c7426db86806a9d447..f4d1056eb8d892a650ae9501f51c84b3d9ba021a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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