X Tutup
Skip to content

Commit 3420abd

Browse files
author
Steve Canny
committed
acpt: add InlineShape.type scenario
1 parent 2d752b7 commit 3420abd

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

docx/enum/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Enumerations used in python-docx
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
10+
class Enumeration(object):
11+
12+
@classmethod
13+
def from_xml(cls, xml_val):
14+
return cls._xml_to_idx[xml_val]
15+
16+
@classmethod
17+
def to_xml(cls, enum_val):
18+
return cls._idx_to_xml[enum_val]

docx/enum/shape.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Enumerations related to DrawingML shapes in WordprocessingML files
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
10+
class WD_INLINE_SHAPE_TYPE(object):
11+
"""
12+
Corresponds to WdInlineShapeType enumeration
13+
http://msdn.microsoft.com/en-us/library/office/ff192587.aspx
14+
"""
15+
PICTURE = 3
16+
LINKED_PICTURE = 4
17+
NOT_IMPLEMENTED = -6
18+
19+
WD_INLINE_SHAPE = WD_INLINE_SHAPE_TYPE

features/shp-inline-shape-access.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ Feature: Access inline shapes in document
1212
Given an inline shape collection containing two shapes
1313
Then I can iterate over the inline shape collection
1414
And I can access an inline shape by index
15+
16+
@wip
17+
Scenario Outline: Identify type of inline shape
18+
Given an inline shape known to be <shape of type>
19+
Then its inline shape type is <shape type>
20+
21+
Examples: Inline shapes of recognized types
22+
| shape of type | shape type |
23+
| an embedded picture | WD_INLINE_SHAPE.PICTURE |
24+
| a linked picture | WD_INLINE_SHAPE.LINKED_PICTURE |

features/steps/shape.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from behave import given, then
1010

1111
from docx import Document
12+
from docx.enum.shape import WD_INLINE_SHAPE
1213
from docx.parts import InlineShape, InlineShapes
1314

1415
from .helpers import test_docx
@@ -29,6 +30,17 @@ def given_inline_shape_collection_containing_two_shapes(context):
2930
context.inline_shapes = document.inline_shapes
3031

3132

33+
@given('an inline shape known to be {shp_of_type}')
34+
def given_inline_shape_known_to_be_shape_of_type(context, shp_of_type):
35+
inline_shape_idx = {
36+
'an embedded picture': 0,
37+
'a linked picture': 1,
38+
}[shp_of_type]
39+
docx_path = test_docx('shp-inline-shape-access')
40+
document = Document(docx_path)
41+
context.inline_shape = document.inline_shapes[inline_shape_idx]
42+
43+
3244
# then =====================================================
3345

3446
@then('I can access an inline shape by index')
@@ -56,6 +68,16 @@ def then_can_iterate_over_inline_shape_collection(context):
5668
assert actual_count == 2
5769

5870

71+
@then('its inline shape type is {shape_type}')
72+
def then_inline_shape_type_is_shape_type(context, shape_type):
73+
expected_value = {
74+
'WD_INLINE_SHAPE.PICTURE': WD_INLINE_SHAPE.PICTURE,
75+
'WD_INLINE_SHAPE.LINKED_PICTURE': WD_INLINE_SHAPE.LINKED_PICTURE,
76+
}[shape_type]
77+
inline_shape = context.inline_shape
78+
assert inline_shape.type == expected_value
79+
80+
5981
@then('the length of the inline shape collection is 2')
6082
def then_len_of_inline_shape_collection_is_2(context):
6183
inline_shapes = context.document.inline_shapes
62.8 KB
Loading
-62.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)
X Tutup