[Python-checkins] cpython (3.4): Issue #24857: Comparing call_args to a long sequence now correctly returns a

berker.peksag python-checkins at python.org
Wed Sep 9 22:40:35 CEST 2015


https://hg.python.org/cpython/rev/83ea55a1204a
changeset:   97833:83ea55a1204a
branch:      3.4
parent:      97804:da9b26670e44
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Wed Sep 09 23:35:25 2015 +0300
summary:
  Issue #24857: Comparing call_args to a long sequence now correctly returns a
boolean result instead of raising an exception.

Patch by A Kaptur.

files:
  Lib/unittest/mock.py                   |  5 +++--
  Lib/unittest/test/testmock/testmock.py |  3 +++
  Misc/NEWS                              |  3 +++
  3 files changed, 9 insertions(+), 2 deletions(-)


diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1986,8 +1986,7 @@
             else:
                 other_args = ()
                 other_kwargs = value
-        else:
-            # len 2
+        elif len_other == 2:
             # could be (name, args) or (name, kwargs) or (args, kwargs)
             first, second = other
             if isinstance(first, str):
@@ -1998,6 +1997,8 @@
                     other_args, other_kwargs = (), second
             else:
                 other_args, other_kwargs = first, second
+        else:
+            return False
 
         if self_name and other_name != self_name:
             return False
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
@@ -291,6 +291,9 @@
         self.assertEqual(mock.call_args,
                          ((sentinel.Arg,), {"kw": sentinel.Kwarg}))
 
+        # Comparing call_args to a long sequence should not raise
+        # an exception. See issue 24857.
+        self.assertFalse(mock.call_args == "a long sequence")
 
     def test_assert_called_with(self):
         mock = Mock()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -84,6 +84,9 @@
 - Issue #24982: shutil.make_archive() with the "zip" format now adds entries
   for directories (including empty directories) in ZIP file.
 
+- Issue #24857: Comparing call_args to a long sequence now correctly returns a
+  boolean result instead of raising an exception.  Patch by A Kaptur.
+
 - Issue #25019: Fixed a crash caused by setting non-string key of expat parser.
   Based on patch by John Leitch.
 

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


More information about the Python-checkins mailing list