|
18 | 18 | from docx.package import ImageParts, Package |
19 | 19 | from docx.parts.document import _Body, DocumentPart, InlineShapes, Sections |
20 | 20 | from docx.parts.image import ImagePart |
| 21 | +from docx.section import Section |
21 | 22 | from docx.shape import InlineShape |
22 | 23 | from docx.table import Table |
23 | 24 | from docx.text import Paragraph |
@@ -626,17 +627,35 @@ def it_knows_how_many_sections_it_contains(self, len_fixture): |
626 | 627 | print(sections._document_elm.xml) |
627 | 628 | assert len(sections) == expected_len |
628 | 629 |
|
| 630 | + def it_can_iterate_over_its_Section_instances(self, iter_fixture): |
| 631 | + sections, expected_count = iter_fixture |
| 632 | + section_count = 0 |
| 633 | + for section in sections: |
| 634 | + section_count += 1 |
| 635 | + assert isinstance(section, Section) |
| 636 | + assert section_count == expected_count |
| 637 | + |
629 | 638 | # fixtures ------------------------------------------------------- |
630 | 639 |
|
631 | 640 | @pytest.fixture |
632 | | - def len_fixture(self): |
633 | | - document_elm = ( |
| 641 | + def iter_fixture(self, document_elm): |
| 642 | + sections = Sections(document_elm) |
| 643 | + return sections, 2 |
| 644 | + |
| 645 | + @pytest.fixture |
| 646 | + def len_fixture(self, document_elm): |
| 647 | + sections = Sections(document_elm) |
| 648 | + return sections, 2 |
| 649 | + |
| 650 | + # fixture components --------------------------------------------- |
| 651 | + |
| 652 | + @pytest.fixture |
| 653 | + def document_elm(self): |
| 654 | + return ( |
634 | 655 | a_document().with_nsdecls().with_child( |
635 | 656 | a_body().with_child( |
636 | 657 | a_p().with_child( |
637 | 658 | a_pPr().with_child( |
638 | 659 | a_sectPr()))).with_child( |
639 | 660 | a_sectPr())) |
640 | 661 | ).element |
641 | | - sections = Sections(document_elm) |
642 | | - return sections, 2 |
|
0 commit comments