From: Berker Peksag Date: Wed, 9 Sep 2015 20:35:25 +0000 (+0300) Subject: Issue #24857: Comparing call_args to a long sequence now correctly returns a X-Git-Tag: v3.5.1rc1~405^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3fc536f1c95abdd57bc4172fb8eb96fd86cab4d3;p=python Issue #24857: Comparing call_args to a long sequence now correctly returns a boolean result instead of raising an exception. Patch by A Kaptur. --- diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index ec3f2f9e42..573c799ced 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1986,8 +1986,7 @@ class _Call(tuple): 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 @@ class _Call(tuple): 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 index 976c40fc45..cf1673c6ca 100644 --- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py @@ -291,6 +291,9 @@ class MockTest(unittest.TestCase): 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 index 79faea9710..01913a5086 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -84,6 +84,9 @@ Library - 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.