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

Skip to content

Commit 3fc536f

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.
1 parent d1a9858 commit 3fc536f

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
@@ -1986,8 +1986,7 @@ def __eq__(self, other):
19861986
else:
19871987
other_args = ()
19881988
other_kwargs = value
1989-
else:
1990-
# len 2
1989+
elif len_other == 2:
19911990
# could be (name, args) or (name, kwargs) or (args, kwargs)
19921991
first, second = other
19931992
if isinstance(first, str):
@@ -1998,6 +1997,8 @@ def __eq__(self, other):
19981997
other_args, other_kwargs = (), second
19991998
else:
20001999
other_args, other_kwargs = first, second
2000+
else:
2001+
return False
20012002

20022003
if self_name and other_name != self_name:
20032004
return False

Lib/unittest/test/testmock/testmock.py

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

294+
# Comparing call_args to a long sequence should not raise
295+
# an exception. See issue 24857.
296+
self.assertFalse(mock.call_args == "a long sequence")
294297

295298
def test_assert_called_with(self):
296299
mock = Mock()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ Library
8484
- Issue #24982: shutil.make_archive() with the "zip" format now adds entries
8585
for directories (including empty directories) in ZIP file.
8686

87+
- Issue #24857: Comparing call_args to a long sequence now correctly returns a
88+
boolean result instead of raising an exception. Patch by A Kaptur.
89+
8790
- Issue #25019: Fixed a crash caused by setting non-string key of expat parser.
8891
Based on patch by John Leitch.
8992

0 commit comments

Comments
 (0)