MCPcopy Index your code
hub / github.com/python/cpython / test_assert_has_calls

Method test_assert_has_calls

Lib/test/test_unittest/testmock/testmock.py:1510–1547  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1508 )
1509
1510 def test_assert_has_calls(self):
1511 kalls1 = [
1512 call(1, 2), ({'a': 3},),
1513 ((3, 4),), call(b=6),
1514 ('', (1,), {'b': 6}),
1515 ]
1516 kalls2 = [call.foo(), call.bar(1)]
1517 kalls2.extend(call.spam().baz(a=3).call_list())
1518 kalls2.extend(call.bam(set(), foo={}).fish([1]).call_list())
1519
1520 mocks = []
1521 for mock in Mock(), MagicMock():
1522 mock(1, 2)
1523 mock(a=3)
1524 mock(3, 4)
1525 mock(b=6)
1526 mock(1, b=6)
1527 mocks.append((mock, kalls1))
1528
1529 mock = Mock()
1530 mock.foo()
1531 mock.bar(1)
1532 mock.spam().baz(a=3)
1533 mock.bam(set(), foo={}).fish([1])
1534 mocks.append((mock, kalls2))
1535
1536 for mock, kalls in mocks:
1537 for i in range(len(kalls)):
1538 for step in 1, 2, 3:
1539 these = kalls[i:i+step]
1540 mock.assert_has_calls(these)
1541
1542 if len(these) > 1:
1543 self.assertRaises(
1544 AssertionError,
1545 mock.assert_has_calls,
1546 list(reversed(these))
1547 )
1548
1549
1550 def test_assert_has_calls_nested_spec(self):

Callers

nothing calls this directly

Calls 14

MockClass · 0.90
MagicMockClass · 0.90
setFunction · 0.85
listClass · 0.85
call_listMethod · 0.80
assert_has_callsMethod · 0.80
callFunction · 0.50
fooMethod · 0.45
barMethod · 0.45
extendMethod · 0.45
bazMethod · 0.45
spamMethod · 0.45

Tested by

no test coverage detected