mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
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 <neal@nealfinne.com>
This commit is contained in:
parent
ad99a9d4c2
commit
49c5310ad4
1 changed files with 20 additions and 0 deletions
|
|
@ -322,6 +322,16 @@ class CallTest(unittest.TestCase):
|
||||||
kall = call(1).method(2)(3).foo.bar.baz(4)(5).__int__()
|
kall = call(1).method(2)(3).foo.bar.baz(4)(5).__int__()
|
||||||
self.assertEqual(kall.call_list(), mock.mock_calls)
|
self.assertEqual(kall.call_list(), mock.mock_calls)
|
||||||
|
|
||||||
|
def test_call_list_with_any_comparison_order(self):
|
||||||
|
class Foo:
|
||||||
|
def __eq__(self, other): pass
|
||||||
|
def __ne__(self, other): pass
|
||||||
|
|
||||||
|
mock = MagicMock()
|
||||||
|
mock(Foo())
|
||||||
|
|
||||||
|
self.assertEqual(call(ANY).call_list(), mock.mock_calls)
|
||||||
|
self.assertEqual(mock.mock_calls, call(ANY).call_list())
|
||||||
|
|
||||||
def test_call_any(self):
|
def test_call_any(self):
|
||||||
self.assertEqual(call, ANY)
|
self.assertEqual(call, ANY)
|
||||||
|
|
@ -331,6 +341,16 @@ class CallTest(unittest.TestCase):
|
||||||
self.assertEqual(m.mock_calls, [ANY])
|
self.assertEqual(m.mock_calls, [ANY])
|
||||||
self.assertEqual([ANY], m.mock_calls)
|
self.assertEqual([ANY], m.mock_calls)
|
||||||
|
|
||||||
|
def test_call_any_comparison_order(self):
|
||||||
|
class Foo:
|
||||||
|
def __eq__(self, other): pass
|
||||||
|
def __ne__(self, other): pass
|
||||||
|
|
||||||
|
m = MagicMock()
|
||||||
|
m(Foo())
|
||||||
|
|
||||||
|
self.assertEqual(m.mock_calls[0], call(ANY))
|
||||||
|
self.assertEqual(call(ANY), m.mock_calls[0])
|
||||||
|
|
||||||
def test_two_args_call(self):
|
def test_two_args_call(self):
|
||||||
args = _Call(((1, 2), {'a': 3}), two=True)
|
args = _Call(((1, 2), {'a': 3}), two=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue