22
33import pytest
44
5+ from docx import Document
56from docx .blkcntnr import BlockItemContainer
67from docx .shared import Inches
78from docx .table import Table
89from docx .text .paragraph import Paragraph
910
1011from .unitutil .cxml import element , xml
11- from .unitutil .file import snippet_seq
12+ from .unitutil .file import snippet_seq , test_file
1213from .unitutil .mock import call , instance_mock , method_mock
1314
1415
@@ -34,6 +35,26 @@ def it_can_add_a_table(self, add_table_fixture):
3435 assert table ._element .xml == expected_xml
3536 assert table ._parent is blkcntnr
3637
38+ def it_can_iterate_its_inner_content (self ):
39+ document = Document (test_file ("blk-inner-content.docx" ))
40+
41+ inner_content = document .iter_inner_content ()
42+
43+ para = next (inner_content )
44+ assert isinstance (para , Paragraph )
45+ assert para .text == "P1"
46+ # --
47+ t = next (inner_content )
48+ assert isinstance (t , Table )
49+ assert t .rows [0 ].cells [0 ].text == "T2"
50+ # --
51+ para = next (inner_content )
52+ assert isinstance (para , Paragraph )
53+ assert para .text == "P3"
54+ # --
55+ with pytest .raises (StopIteration ):
56+ next (inner_content )
57+
3758 def it_provides_access_to_the_paragraphs_it_contains (self , paragraphs_fixture ):
3859 # test len(), iterable, and indexed access
3960 blkcntnr , expected_count = paragraphs_fixture
0 commit comments