Skip to content

Commit f858527

Browse files
author
Steve Canny
committed
acpt: add shp-inline-shape-access.feature
1 parent 6674d3c commit f858527

File tree

5 files changed

+92
-21
lines changed

5 files changed

+92
-21
lines changed

docs/dev/analysis/features/shapes-inline.rst

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,6 @@ inline shape::
2222
>>> assert inline_shape.type == MSO_SHAPE_TYPE.PICTURE
2323

2424

25-
Acceptance test
26-
---------------
27-
28-
shp-inline-shape-access.feature::
29-
30-
Feature: Access inline shapes in document
31-
In order to query or manipulate inline shapes in a document
32-
As an python-docx developer
33-
I need the ability to access the inline shapes in a document
34-
35-
Scenario: Access inline shapes collection of document
36-
Given a document having two inline shapes
37-
Then I can access the inline shape collection of the document
38-
And the length of the inline shape collection is 2
39-
40-
Scenario: Access shape in inline shape collection
41-
Given an inline shape collection containing two shapes
42-
Then I can iterate over the inline shape collection
43-
And I can access an inline shape by index
44-
45-
4625
Resources
4726
---------
4827

docx/parts.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,17 @@ def tables(self):
8888
they appear.
8989
"""
9090
return [Table(tbl) for tbl in self._body.tbl_lst]
91+
92+
93+
class InlineShape(object):
94+
"""
95+
Proxy for an ``<wp:inline>`` element, representing the container for an
96+
inline graphical object.
97+
"""
98+
99+
100+
class InlineShapes(object):
101+
"""
102+
Sequence of |InlineShape| instances, supporting len(), iteration, and
103+
indexed access.
104+
"""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Feature: Access inline shapes in document
2+
In order to query or manipulate inline shapes in a document
3+
As an python-docx developer
4+
I need the ability to access the inline shapes in a document
5+
6+
@wip
7+
Scenario: Access inline shapes collection of document
8+
Given a document containing two inline shapes
9+
Then I can access the inline shape collection of the document
10+
And the length of the inline shape collection is 2
11+
12+
@wip
13+
Scenario: Access shape in inline shape collection
14+
Given an inline shape collection containing two shapes
15+
Then I can iterate over the inline shape collection
16+
And I can access an inline shape by index

features/steps/shape.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Step implementations for graphical object (shape) related features
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
from behave import given, then
10+
11+
from docx import Document
12+
from docx.parts import InlineShape, InlineShapes
13+
14+
from .helpers import test_docx
15+
16+
17+
# given ===================================================
18+
19+
@given('a document containing two inline shapes')
20+
def given_a_document_containing_two_inline_shapes(context):
21+
docx_path = test_docx('shp-inline-shape-access')
22+
context.document = Document(docx_path)
23+
24+
25+
@given('an inline shape collection containing two shapes')
26+
def given_inline_shape_collection_containing_two_shapes(context):
27+
docx_path = test_docx('shp-inline-shape-access')
28+
document = Document(docx_path)
29+
context.inline_shapes = document.body.inline_shapes
30+
31+
32+
# then =====================================================
33+
34+
@then('I can access an inline shape by index')
35+
def then_can_access_inline_shape_by_index(context):
36+
inline_shapes = context.inline_shapes
37+
for idx in range(2):
38+
inline_shape = inline_shapes[idx]
39+
assert isinstance(inline_shape, InlineShape)
40+
41+
42+
@then('I can access the inline shape collection of the document')
43+
def then_can_access_inline_shape_collection_of_document(context):
44+
document = context.document
45+
inline_shapes = document.inline_shapes
46+
assert isinstance(inline_shapes, InlineShapes)
47+
48+
49+
@then('I can iterate over the inline shape collection')
50+
def then_can_iterate_over_inline_shape_collection(context):
51+
inline_shapes = context.inline_shapes
52+
actual_count = 0
53+
for inline_shape in inline_shapes:
54+
actual_count += 1
55+
assert isinstance(inline_shape, InlineShape)
56+
assert actual_count == 2
57+
58+
59+
@then('the length of the inline shape collection is 2')
60+
def then_len_of_inline_shape_collection_is_2(context):
61+
inline_shapes = context.document.inline_shapes
62+
assert len(inline_shapes) == 2
122 KB
Binary file not shown.

0 commit comments

Comments
 (0)