Skip to content

Commit 49c5310

Browse files
ElizabethUnealfinne
andcommitted
bpo-37555: Add regression tests for mock ANY ordering issues
Add regression tests for whether __eq__ is order agnostic on _Call and _CallList, which is useful for comparisons involving ANY, especially if the ANY comparison is to a class not defaulting __eq__ to NotImplemented. Co-authored-by: Neal Finne <[email protected]>
1 parent ad99a9d commit 49c5310

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/unittest/test/testmock/testhelpers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ def test_call_list(self):
322322
kall = call(1).method(2)(3).foo.bar.baz(4)(5).__int__()
323323
self.assertEqual(kall.call_list(), mock.mock_calls)
324324

325+
def test_call_list_with_any_comparison_order(self):
326+
class Foo:
327+
def __eq__(self, other): pass
328+
def __ne__(self, other): pass
329+
330+
mock = MagicMock()
331+
mock(Foo())
332+
333+
self.assertEqual(call(ANY).call_list(), mock.mock_calls)
334+
self.assertEqual(mock.mock_calls, call(ANY).call_list())
325335

326336
def test_call_any(self):
327337
self.assertEqual(call, ANY)
@@ -331,6 +341,16 @@ def test_call_any(self):
331341
self.assertEqual(m.mock_calls, [ANY])
332342
self.assertEqual([ANY], m.mock_calls)
333343

344+
def test_call_any_comparison_order(self):
345+
class Foo:
346+
def __eq__(self, other): pass
347+
def __ne__(self, other): pass
348+
349+
m = MagicMock()
350+
m(Foo())
351+
352+
self.assertEqual(m.mock_calls[0], call(ANY))
353+
self.assertEqual(call(ANY), m.mock_calls[0])
334354

335355
def test_two_args_call(self):
336356
args = _Call(((1, 2), {'a': 3}), two=True)

0 commit comments

Comments
 (0)