11
11
from docx import Document
12
12
from docx .enum .section import WD_ORIENT , WD_SECTION
13
13
from docx .parts .document import InlineShapes , Sections
14
- from docx .section import Section
15
14
from docx .shared import Inches
16
15
from docx .table import Table
17
16
@@ -30,17 +29,11 @@ def given_a_document_having_inline_shapes(context):
30
29
context .document = Document (test_docx ('shp-inline-shape-access' ))
31
30
32
31
33
- @given ('a document having three sections' )
34
- def given_a_document_having_three_sections (context ):
32
+ @given ('a document having sections' )
33
+ def given_a_document_having_sections (context ):
35
34
context .document = Document (test_docx ('doc-access-sections' ))
36
35
37
36
38
- @given ('a section collection' )
39
- def given_a_section_collection (context ):
40
- document = Document (test_docx ('doc-access-sections' ))
41
- context .sections = document .sections
42
-
43
-
44
37
@given ('a single-section document having portrait layout' )
45
38
def given_a_single_section_document_having_portrait_layout (context ):
46
39
context .document = Document (test_docx ('doc-add-section' ))
@@ -151,44 +144,26 @@ def when_I_change_the_new_section_layout_to_landscape(context):
151
144
152
145
# then ====================================================
153
146
154
- @then ('document.paragraphs is a list containing three paragraphs' )
155
- def then_document_paragraphs_is_a_list_containing_three_paragraphs (context ):
156
- document = context .document
157
- paragraphs = document .paragraphs
158
- assert isinstance (paragraphs , list )
159
- assert len (paragraphs ) == 3
160
-
161
-
162
- @then ('I can access a section by index' )
163
- def then_I_can_access_a_section_by_index (context ):
164
- sections = context .sections
165
- for idx in range (3 ):
166
- section = sections [idx ]
167
- assert isinstance (section , Section )
168
-
169
-
170
- @then ('I can access the inline shape collection of the document' )
171
- def then_can_access_inline_shape_collection_of_document (context ):
147
+ @then ('document.inline_shapes is an InlineShapes object' )
148
+ def then_document_inline_shapes_is_an_InlineShapes_object (context ):
172
149
document = context .document
173
150
inline_shapes = document .inline_shapes
174
151
assert isinstance (inline_shapes , InlineShapes )
175
152
176
153
177
- @then ('I can access the section collection of the document ' )
178
- def then_I_can_access_the_section_collection_of_the_document (context ):
154
+ @then ('document.sections is a Sections object ' )
155
+ def then_document_sections_is_a_Sections_object (context ):
179
156
sections = context .document .sections
180
157
msg = 'document.sections not instance of Sections'
181
158
assert isinstance (sections , Sections ), msg
182
159
183
160
184
- @then ('I can iterate over the sections' )
185
- def then_I_can_iterate_over_the_sections (context ):
186
- sections = context .sections
187
- actual_count = 0
188
- for section in sections :
189
- actual_count += 1
190
- assert isinstance (section , Section )
191
- assert actual_count == 3
161
+ @then ('document.paragraphs is a list containing three paragraphs' )
162
+ def then_document_paragraphs_is_a_list_containing_three_paragraphs (context ):
163
+ document = context .document
164
+ paragraphs = document .paragraphs
165
+ assert isinstance (paragraphs , list )
166
+ assert len (paragraphs ) == 3
192
167
193
168
194
169
@then ('the document contains a 2 x 2 table' )
@@ -232,14 +207,6 @@ def then_last_p_contains_heading_text(context):
232
207
assert paragraph .text == text
233
208
234
209
235
- @then ('the length of the section collection is 3' )
236
- def then_the_length_of_the_section_collection_is_3 (context ):
237
- sections = context .document .sections
238
- assert len (sections ) == 3 , (
239
- 'expected len(sections) of 2, got %s' % len (sections )
240
- )
241
-
242
-
243
210
@then ('the second section is landscape' )
244
211
def then_the_second_section_is_landscape (context ):
245
212
new_section = context .document .sections [- 1 ]
0 commit comments