1111from docx import Document
1212from docx .enum .section import WD_ORIENT , WD_SECTION
1313from docx .parts .document import InlineShapes , Sections
14- from docx .section import Section
1514from docx .shared import Inches
1615from docx .table import Table
1716
@@ -30,17 +29,11 @@ def given_a_document_having_inline_shapes(context):
3029 context .document = Document (test_docx ('shp-inline-shape-access' ))
3130
3231
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 ):
3534 context .document = Document (test_docx ('doc-access-sections' ))
3635
3736
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-
4437@given ('a single-section document having portrait layout' )
4538def given_a_single_section_document_having_portrait_layout (context ):
4639 context .document = Document (test_docx ('doc-add-section' ))
@@ -151,44 +144,26 @@ def when_I_change_the_new_section_layout_to_landscape(context):
151144
152145# then ====================================================
153146
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 ):
172149 document = context .document
173150 inline_shapes = document .inline_shapes
174151 assert isinstance (inline_shapes , InlineShapes )
175152
176153
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 ):
179156 sections = context .document .sections
180157 msg = 'document.sections not instance of Sections'
181158 assert isinstance (sections , Sections ), msg
182159
183160
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
192167
193168
194169@then ('the document contains a 2 x 2 table' )
@@ -232,14 +207,6 @@ def then_last_p_contains_heading_text(context):
232207 assert paragraph .text == text
233208
234209
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-
243210@then ('the second section is landscape' )
244211def then_the_second_section_is_landscape (context ):
245212 new_section = context .document .sections [- 1 ]
0 commit comments