|
13 | 13 |
|
14 | 14 | import pytest |
15 | 15 |
|
16 | | -from mock import Mock |
| 16 | +from mock import call, Mock |
17 | 17 |
|
| 18 | +from .unitdata import a_body |
18 | 19 | from .unitutil import class_mock, function_mock, initializer_mock |
19 | 20 |
|
20 | 21 |
|
@@ -75,3 +76,21 @@ def it_can_add_a_paragraph_to_itself(self, Paragraph_): |
75 | 76 | body_elm.add_p.assert_called_once_with() |
76 | 77 | Paragraph_.assert_called_once_with(p_elm) |
77 | 78 | assert p is Paragraph_.return_value |
| 79 | + |
| 80 | + def it_provides_access_to_its_paragraphs_as_a_sequence(self, Paragraph_): |
| 81 | + # mockery ---------------------- |
| 82 | + body_elm = Mock(name='body_elm') |
| 83 | + p1, p2 = (Mock(name='p1'), Mock(name='p2')) |
| 84 | + P1, P2 = (Mock(name='Paragraph1'), Mock(name='Paragraph2')) |
| 85 | + body_elm.p = [p1, p2] |
| 86 | + body = _Body(body_elm) |
| 87 | + Paragraph_.side_effect = [P1, P2] |
| 88 | + # exercise --------------------- |
| 89 | + paragraphs = body.paragraphs |
| 90 | + # verify ----------------------- |
| 91 | + assert Paragraph_.mock_calls == [call(p1), call(p2)] |
| 92 | + assert paragraphs == (P1, P2) |
| 93 | + |
| 94 | + def it_returns_an_empty_sequence_when_it_contains_no_paragraphs(self): |
| 95 | + body = _Body(a_body().element) |
| 96 | + assert body.paragraphs == () |
0 commit comments