Skip to content

Commit 026db1b

Browse files
author
Steve Canny
committed
doc: add Document.inline_shapes
1 parent 2350c52 commit 026db1b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

docx/document.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ def core_properties(self):
106106
"""
107107
return self._part.core_properties
108108

109+
@property
110+
def inline_shapes(self):
111+
"""
112+
An |InlineShapes| object providing access to the inline shapes in
113+
this document. An inline shape is a graphical object, such as
114+
a picture, contained in a run of text and behaving like a character
115+
glyph, being flowed like other text in a paragraph.
116+
"""
117+
return self._part.inline_shapes
118+
109119
@property
110120
def part(self):
111121
"""

tests/test_document.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from docx.enum.section import WD_SECTION
1515
from docx.enum.text import WD_BREAK
1616
from docx.opc.coreprops import CoreProperties
17-
from docx.parts.document import DocumentPart
17+
from docx.parts.document import DocumentPart, InlineShapes
1818
from docx.shape import InlineShape
1919
from docx.table import Table
2020
from docx.text.paragraph import Paragraph
@@ -84,6 +84,11 @@ def it_provides_access_to_its_core_properties(self, core_props_fixture):
8484
core_properties = document.core_properties
8585
assert core_properties is core_properties_
8686

87+
def it_provides_access_to_its_inline_shapes(self, inline_shapes_fixture):
88+
document, inline_shapes_ = inline_shapes_fixture
89+
inline_shapes = document.inline_shapes
90+
assert inline_shapes is inline_shapes_
91+
8792
def it_provides_access_to_the_document_part(self, part_fixture):
8893
document, part_ = part_fixture
8994
assert document.part is part_
@@ -174,6 +179,12 @@ def core_props_fixture(self, document_part_, core_properties_):
174179
document_part_.core_properties = core_properties_
175180
return document, core_properties_
176181

182+
@pytest.fixture
183+
def inline_shapes_fixture(self, document_part_, inline_shapes_):
184+
document = Document(None, document_part_)
185+
document_part_.inline_shapes = inline_shapes_
186+
return document, inline_shapes_
187+
177188
@pytest.fixture
178189
def part_fixture(self, document_part_):
179190
document = Document(None, document_part_)
@@ -205,6 +216,10 @@ def core_properties_(self, request):
205216
def document_part_(self, request):
206217
return instance_mock(request, DocumentPart)
207218

219+
@pytest.fixture
220+
def inline_shapes_(self, request):
221+
return instance_mock(request, InlineShapes)
222+
208223
@pytest.fixture
209224
def paragraph_(self, request):
210225
return instance_mock(request, Paragraph)

0 commit comments

Comments
 (0)