Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17ebaa9

Browse files
committed
Issue #24857: Comparing call_args to a long sequence now correctly returns a
boolean result instead of raising an exception. Patch by A Kaptur.
2 parents 0ae505e + 29bf4d4 commit 17ebaa9

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/unittest/mock.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,8 +2005,7 @@ def __eq__(self, other):
20052005
else:
20062006
other_args = ()
20072007
other_kwargs = value
2008-
else:
2009-
# len 2
2008+
elif len_other == 2:
20102009
# could be (name, args) or (name, kwargs) or (args, kwargs)
20112010
first, second = other
20122011
if isinstance(first, str):
@@ -2017,6 +2016,8 @@ def __eq__(self, other):
20172016
other_args, other_kwargs = (), second
20182017
else:
20192018
other_args, other_kwargs = first, second
2019+
else:
2020+
return False
20202021

20212022
if self_name and other_name != self_name:
20222023
return False

Lib/unittest/test/testmock/testmock.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ def test_call_args_comparison(self):
300300
self.assertEqual(mock.call_args,
301301
((sentinel.Arg,), {"kw": sentinel.Kwarg}))
302302

303+
# Comparing call_args to a long sequence should not raise
304+
# an exception. See issue 24857.
305+
self.assertFalse(mock.call_args == "a long sequence")
303306

304307
def test_assert_called_with(self):
305308
mock = Mock()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ Core and Builtins
9898
Library
9999
-------
100100

101+
- Issue #24857: Comparing call_args to a long sequence now correctly returns a
102+
boolean result instead of raising an exception. Patch by A Kaptur.
103+
101104
- Issue #23144: Make sure that HTMLParser.feed() returns all the data, even
102105
when convert_charrefs is True.
103106

0 commit comments

Comments
 (0)