File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ class InlineShape(object):
104104 Proxy for an ``<wp:inline>`` element, representing the container for an
105105 inline graphical object.
106106 """
107+ def __init__ (self , inline ):
108+ super (InlineShape , self ).__init__ ()
109+ self ._inline = inline
107110
108111
109112class InlineShapes (object ):
@@ -115,8 +118,14 @@ def __init__(self, body_elm):
115118 super (InlineShapes , self ).__init__ ()
116119 self ._body = body_elm
117120
121+ def __iter__ (self ):
122+ return (InlineShape (inline ) for inline in self ._inline_lst )
123+
118124 def __len__ (self ):
125+ return len (self ._inline_lst )
126+
127+ @property
128+ def _inline_lst (self ):
119129 body = self ._body
120130 xpath = './w:p/w:r/w:drawing/wp:inline'
121- inline_elms = body .xpath (xpath , namespaces = nsmap )
122- return len (inline_elms )
131+ return body .xpath (xpath , namespaces = nsmap )
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def given_a_document_containing_two_inline_shapes(context):
2626def given_inline_shape_collection_containing_two_shapes (context ):
2727 docx_path = test_docx ('shp-inline-shape-access' )
2828 document = Document (docx_path )
29- context .inline_shapes = document .body . inline_shapes
29+ context .inline_shapes = document .inline_shapes
3030
3131
3232# then =====================================================
Original file line number Diff line number Diff line change 1111from mock import Mock
1212
1313from docx .oxml .parts import CT_Document
14- from docx .parts import _Body , _Document , InlineShapes
14+ from docx .parts import _Body , _Document , InlineShape , InlineShapes
1515from docx .table import Table
1616from docx .text import Paragraph
1717
@@ -264,6 +264,15 @@ def it_knows_how_many_inline_shapes_it_contains(
264264 print (inline_shapes ._body .xml )
265265 assert len (inline_shapes ) == inline_shape_count
266266
267+ def it_can_iterate_over_its_InlineShape_instances (
268+ self , inline_shapes_fixture ):
269+ inline_shapes , inline_shape_count = inline_shapes_fixture
270+ actual_count = 0
271+ for inline_shape in inline_shapes :
272+ assert isinstance (inline_shape , InlineShape )
273+ actual_count += 1
274+ assert actual_count == inline_shape_count
275+
267276 # fixtures -------------------------------------------------------
268277
269278 @pytest .fixture
You can’t perform that action at this time.
0 commit comments