88
99import pytest
1010
11- from mock import call , Mock
11+ from mock import Mock
12+
13+ from docx .text import Paragraph
1214
1315from .oxml .unitdata .parts import a_body
16+ from .oxml .unitdata .text import a_p
1417from .unitutil import class_mock , function_mock , initializer_mock
1518
1619
@@ -86,20 +89,6 @@ def it_can_add_a_paragraph_to_itself(self, Paragraph_):
8689 Paragraph_ .assert_called_once_with (p_elm )
8790 assert p is Paragraph_ .return_value
8891
89- def it_provides_access_to_its_paragraphs_as_a_sequence (self , Paragraph_ ):
90- # mockery ----------------------
91- body_elm = Mock (name = 'body_elm' )
92- p1 , p2 = (Mock (name = 'p1' ), Mock (name = 'p2' ))
93- P1 , P2 = (Mock (name = 'Paragraph1' ), Mock (name = 'Paragraph2' ))
94- body_elm .p_lst = [p1 , p2 ]
95- body = _Body (body_elm )
96- Paragraph_ .side_effect = [P1 , P2 ]
97- # exercise ---------------------
98- paragraphs = body .paragraphs
99- # verify -----------------------
100- assert Paragraph_ .mock_calls == [call (p1 ), call (p2 )]
101- assert paragraphs == [P1 , P2 ]
102-
10392 def it_returns_an_empty_sequence_when_it_contains_no_paragraphs (self ):
10493 body = _Body (a_body ().with_nsdecls ().element )
10594 assert body .paragraphs == []
@@ -114,8 +103,26 @@ def it_can_clear_itself_of_all_content_it_holds(self):
114103 body_elm .clear_content .assert_called_once_with ()
115104 assert retval is body
116105
106+ def it_provides_access_to_the_paragraphs_it_contains (
107+ self , body_with_paragraphs ):
108+ body = body_with_paragraphs
109+ paragraphs = body .paragraphs
110+ assert len (paragraphs ) == 2
111+ for p in paragraphs :
112+ assert isinstance (p , Paragraph )
113+
117114 # fixtures -------------------------------------------------------
118115
116+ @pytest .fixture
117+ def body_with_paragraphs (self ):
118+ body_elm = (
119+ a_body ().with_nsdecls ()
120+ .with_child (a_p ())
121+ .with_child (a_p ())
122+ .element
123+ )
124+ return _Body (body_elm )
125+
119126 @pytest .fixture
120127 def Paragraph_ (self , request ):
121128 return class_mock (request , 'docx.parts.Paragraph' )
0 commit comments