]> granicus.if.org Git - python/commitdiff
Fix unittest.mock._Call: don't ignore name
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 6 Jan 2017 17:15:51 +0000 (18:15 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 6 Jan 2017 17:15:51 +0000 (18:15 +0100)
Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter
anymore.

Patch written by Jiajun Huang.

Lib/unittest/mock.py
Lib/unittest/test/testmock/testhelpers.py
Misc/NEWS

index f1349198880c63c09769f13cb0e1a9be639a2682..dcac5a2925400b7d113c4430f91454984cd2cdbf 100644 (file)
@@ -1961,9 +1961,8 @@ class _Call(tuple):
 
     If the _Call has no name then it will match any name.
     """
-    def __new__(cls, value=(), name=None, parent=None, two=False,
+    def __new__(cls, value=(), name='', parent=None, two=False,
                 from_kall=True):
-        name = ''
         args = ()
         kwargs = {}
         _len = len(value)
index 34776347daa637419cdf66797ba76269565b498b..d5f9e7c1d69204423244827f2dc60b3c79853a3b 100644 (file)
@@ -306,6 +306,20 @@ class CallTest(unittest.TestCase):
         other_args = _Call(((1, 2), {'a': 3}))
         self.assertEqual(args, other_args)
 
+    def test_call_with_name(self):
+        self.assertEqual(
+            'foo',
+            _Call((), 'foo')[0],
+        )
+        self.assertEqual(
+            '',
+            _Call((('bar', 'barz'), ), )[0]
+        )
+        self.assertEqual(
+            '',
+            _Call((('bar', 'barz'), {'hello': 'world'}), )[0]
+        )
+
 
 class SpecSignatureTest(unittest.TestCase):
 
index 113ca8abbe8467114f81d754e8d7daffb047a0fb..456f8760526821d7b5a4f2644496d2cf0ac9ac26 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -42,6 +42,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter
+  anymore. Patch written by Jiajun Huang.
+
 - Issue #15812: inspect.getframeinfo() now correctly shows the first line of
   a context.  Patch by Sam Breese.