X Tutup
Skip to content

Commit 2350c52

Browse files
author
Steve Canny
committed
acpt: migrate doc-access-collections.feature
* Provide a home for testing access to the various collections in a document. * Segregate access to the collection from access to individual items in the collection.
1 parent f3a2f10 commit 2350c52

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Feature: Access document collections
2+
In order to operate on objects related to a document
3+
As a developer using python-docx
4+
I need a way to access each of the document's collections
5+
6+
7+
Scenario: Access the inline shapes collection of a document
8+
Given a document having inline shapes
9+
Then I can access the inline shape collection of the document

features/shp-inline-shape-access.feature

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
Feature: Access inline shapes in document
2-
In order to query or manipulate inline shapes in a document
1+
Feature: Access inline shape in inline shape collection
2+
In order to operate on an inline shape
33
As a developer using python-docx
4-
I need the ability to access the inline shapes in a document
4+
I need a way to access each inline shape in the inline shape collection
55

6-
Scenario: Access inline shapes collection of document
7-
Given a document containing five inline shapes
8-
Then I can access the inline shape collection of the document
9-
And the length of the inline shape collection is 5
106

117
Scenario: Access shape in inline shape collection
128
Given an inline shape collection containing five shapes
13-
Then I can iterate over the inline shape collection
9+
Then the length of the inline shape collection is 5
10+
And I can iterate over the inline shape collection
1411
And I can access each inline shape by index
1512

13+
1614
Scenario Outline: Identify type of inline shape
1715
Given an inline shape known to be <shape of type>
1816
Then its inline shape type is <shape type>

features/steps/document.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from docx import Document
1212
from docx.enum.section import WD_ORIENT, WD_SECTION
13-
from docx.parts.document import Sections
13+
from docx.parts.document import InlineShapes, Sections
1414
from docx.section import Section
1515
from docx.shared import Inches
1616
from docx.table import Table
@@ -25,6 +25,11 @@ def given_a_blank_document(context):
2525
context.document = Document()
2626

2727

28+
@given('a document having inline shapes')
29+
def given_a_document_having_inline_shapes(context):
30+
context.document = Document(test_docx('shp-inline-shape-access'))
31+
32+
2833
@given('a document having three sections')
2934
def given_a_document_having_three_sections(context):
3035
context.document = Document(test_docx('doc-access-sections'))
@@ -154,6 +159,13 @@ def then_I_can_access_a_section_by_index(context):
154159
assert isinstance(section, Section)
155160

156161

162+
@then('I can access the inline shape collection of the document')
163+
def then_can_access_inline_shape_collection_of_document(context):
164+
document = context.document
165+
inline_shapes = document.inline_shapes
166+
assert isinstance(inline_shapes, InlineShapes)
167+
168+
157169
@then('I can access the section collection of the document')
158170
def then_I_can_access_the_section_collection_of_the_document(context):
159171
sections = context.document.sections

features/steps/shape.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,16 @@
1212

1313
from docx import Document
1414
from docx.enum.shape import WD_INLINE_SHAPE
15-
from docx.parts.document import InlineShape, InlineShapes
15+
from docx.parts.document import InlineShape
1616
from docx.shared import Inches
1717

1818
from helpers import test_docx, test_file
1919

2020

2121
# given ===================================================
2222

23-
@given('a document containing five inline shapes')
24-
def given_a_document_containing_two_inline_shapes(context):
25-
docx_path = test_docx('shp-inline-shape-access')
26-
context.document = Document(docx_path)
27-
28-
2923
@given('an inline shape collection containing five shapes')
30-
def given_inline_shape_collection_containing_two_shapes(context):
24+
def given_an_inline_shape_collection_containing_five_shapes(context):
3125
docx_path = test_docx('shp-inline-shape-access')
3226
document = Document(docx_path)
3327
context.inline_shapes = document.inline_shapes
@@ -89,13 +83,6 @@ def then_can_access_each_inline_shape_by_index(context):
8983
assert isinstance(inline_shape, InlineShape)
9084

9185

92-
@then('I can access the inline shape collection of the document')
93-
def then_can_access_inline_shape_collection_of_document(context):
94-
document = context.document
95-
inline_shapes = document.inline_shapes
96-
assert isinstance(inline_shapes, InlineShapes)
97-
98-
9986
@then('I can iterate over the inline shape collection')
10087
def then_can_iterate_over_inline_shape_collection(context):
10188
inline_shapes = context.inline_shapes
@@ -152,7 +139,7 @@ def then_the_document_contains_the_inline_picture(context):
152139

153140
@then('the length of the inline shape collection is 5')
154141
def then_len_of_inline_shape_collection_is_5(context):
155-
inline_shapes = context.document.inline_shapes
142+
inline_shapes = context.inline_shapes
156143
shape_count = len(inline_shapes)
157144
assert shape_count == 5, 'got %s' % shape_count
158145

0 commit comments

Comments
 (0)
X Tutup