]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix unittest.mock._Call: don't ignore name (#307)
authorBerker Peksag <berker.peksag@gmail.com>
Sun, 26 Feb 2017 13:06:11 +0000 (16:06 +0300)
committerGitHub <noreply@github.com>
Sun, 26 Feb 2017 13:06:11 +0000 (16:06 +0300)
Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter
anymore.

Patch written by Jiajun Huang.

(cherry picked from commits 84b6fb0eea29b3b28a1a11124526b01ec0c9d17a
and dea1536fd3a8424d537794cd53715df0989cbbe1)

Conflicts:

Misc/NEWS

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

index 9bc40bc2d154035a6a2c550dbc48431c17c63598..99658d47a356105db97b19b92972fc3de8715b0d 100644 (file)
@@ -1945,9 +1945,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..d2202a7b4132e99857ce84b19f4afb4b4dccb27d 100644 (file)
@@ -306,6 +306,11 @@ class CallTest(unittest.TestCase):
         other_args = _Call(((1, 2), {'a': 3}))
         self.assertEqual(args, other_args)
 
+    def test_call_with_name(self):
+        self.assertEqual(_Call((), 'foo')[0], 'foo')
+        self.assertEqual(_Call((('bar', 'barz'),),)[0], '')
+        self.assertEqual(_Call((('bar', 'barz'), {'hello': 'world'}),)[0], '')
+
 
 class SpecSignatureTest(unittest.TestCase):
 
index abd4e53ef449ca18b8eec0e596305ae5f224350b..bab13da4342dc426af5b903389e0a38e364d6d5e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@ Extension Modules
 Library
 -------
 
+- Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter
+  anymore. Patch written by Jiajun Huang.
+
 - bpo-29532: Altering a kwarg dictionary passed to functools.partial()
   no longer affects a partial object after creation.