mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)
Also refactor the call recording imolementation and add some notes about its limitations.
This commit is contained in:
parent
3bc0ebab17
commit
8ca0fa9d2f
6 changed files with 125 additions and 24 deletions
|
|
@ -925,6 +925,57 @@ class MockTest(unittest.TestCase):
|
|||
call().__int__().call_list())
|
||||
|
||||
|
||||
def test_child_mock_call_equal(self):
|
||||
m = Mock()
|
||||
result = m()
|
||||
result.wibble()
|
||||
# parent looks like this:
|
||||
self.assertEqual(m.mock_calls, [call(), call().wibble()])
|
||||
# but child should look like this:
|
||||
self.assertEqual(result.mock_calls, [call.wibble()])
|
||||
|
||||
|
||||
def test_mock_call_not_equal_leaf(self):
|
||||
m = Mock()
|
||||
m.foo().something()
|
||||
self.assertNotEqual(m.mock_calls[1], call.foo().different())
|
||||
self.assertEqual(m.mock_calls[0], call.foo())
|
||||
|
||||
|
||||
def test_mock_call_not_equal_non_leaf(self):
|
||||
m = Mock()
|
||||
m.foo().bar()
|
||||
self.assertNotEqual(m.mock_calls[1], call.baz().bar())
|
||||
self.assertNotEqual(m.mock_calls[0], call.baz())
|
||||
|
||||
|
||||
def test_mock_call_not_equal_non_leaf_params_different(self):
|
||||
m = Mock()
|
||||
m.foo(x=1).bar()
|
||||
# This isn't ideal, but there's no way to fix it without breaking backwards compatibility:
|
||||
self.assertEqual(m.mock_calls[1], call.foo(x=2).bar())
|
||||
|
||||
|
||||
def test_mock_call_not_equal_non_leaf_attr(self):
|
||||
m = Mock()
|
||||
m.foo.bar()
|
||||
self.assertNotEqual(m.mock_calls[0], call.baz.bar())
|
||||
|
||||
|
||||
def test_mock_call_not_equal_non_leaf_call_versus_attr(self):
|
||||
m = Mock()
|
||||
m.foo.bar()
|
||||
self.assertNotEqual(m.mock_calls[0], call.foo().bar())
|
||||
|
||||
|
||||
def test_mock_call_repr(self):
|
||||
m = Mock()
|
||||
m.foo().bar().baz.bob()
|
||||
self.assertEqual(repr(m.mock_calls[0]), 'call.foo()')
|
||||
self.assertEqual(repr(m.mock_calls[1]), 'call.foo().bar()')
|
||||
self.assertEqual(repr(m.mock_calls[2]), 'call.foo().bar().baz.bob()')
|
||||
|
||||
|
||||
def test_subclassing(self):
|
||||
class Subclass(Mock):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue