Skip to content

Commit 3c16691

Browse files
committed
xfail: for BlockItemContainer.iter_inner_content()
1 parent e315139 commit 3c16691

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Feature: Iterate paragraphs and tables in document-order
2+
In order to access paragraphs and tables in the same order they appear in the document
3+
As a developer using python-docx
4+
I need the ability to iterate the inner-content of a block-item-container
5+
6+
7+
@wip
8+
Scenario: Document.iter_inner_content()
9+
Given a Document object with paragraphs and tables
10+
Then document.iter_inner_content() produces the block-items in document order
11+
12+
13+
@wip
14+
Scenario: Header.iter_inner_content()
15+
Given a Header object with paragraphs and tables
16+
Then header.iter_inner_content() produces the block-items in document order
17+
18+
19+
@wip
20+
Scenario: Footer.iter_inner_content()
21+
Given a Footer object with paragraphs and tables
22+
Then footer.iter_inner_content() produces the block-items in document order
23+
24+
25+
@wip
26+
Scenario: _Cell.iter_inner_content()
27+
Given a _Cell object with paragraphs and tables
28+
Then cell.iter_inner_content() produces the block-items in document order

features/steps/block.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,33 @@
1111
# given ===================================================
1212

1313

14+
@given("a _Cell object with paragraphs and tables")
15+
def given_a_cell_with_paragraphs_and_tables(context: Context):
16+
context.cell = (
17+
Document(test_docx("blk-paras-and-tables")).tables[1].rows[0].cells[0]
18+
)
19+
20+
21+
@given("a Document object with paragraphs and tables")
22+
def given_a_document_with_paragraphs_and_tables(context: Context):
23+
context.document = Document(test_docx("blk-paras-and-tables"))
24+
25+
1426
@given("a document containing a table")
1527
def given_a_document_containing_a_table(context: Context):
1628
context.document = Document(test_docx("blk-containing-table"))
1729

1830

31+
@given("a Footer object with paragraphs and tables")
32+
def given_a_footer_with_paragraphs_and_tables(context: Context):
33+
context.footer = Document(test_docx("blk-paras-and-tables")).sections[0].footer
34+
35+
36+
@given("a Header object with paragraphs and tables")
37+
def given_a_header_with_paragraphs_and_tables(context: Context):
38+
context.header = Document(test_docx("blk-paras-and-tables")).sections[0].header
39+
40+
1941
@given("a paragraph")
2042
def given_a_paragraph(context: Context):
2143
context.document = Document()
@@ -40,6 +62,34 @@ def when_add_table(context: Context):
4062
# then =====================================================
4163

4264

65+
@then("cell.iter_inner_content() produces the block-items in document order")
66+
def then_cell_iter_inner_content_produces_the_block_items(context: Context):
67+
actual = [type(item).__name__ for item in context.cell.iter_inner_content()]
68+
expected = ["Paragraph", "Table", "Paragraph"]
69+
assert actual == expected, f"expected: {expected}, got: {actual}"
70+
71+
72+
@then("document.iter_inner_content() produces the block-items in document order")
73+
def then_document_iter_inner_content_produces_the_block_items(context: Context):
74+
actual = [type(item).__name__ for item in context.document.iter_inner_content()]
75+
expected = ["Table", "Paragraph", "Table", "Paragraph", "Table", "Paragraph"]
76+
assert actual == expected, f"expected: {expected}, got: {actual}"
77+
78+
79+
@then("footer.iter_inner_content() produces the block-items in document order")
80+
def then_footer_iter_inner_content_produces_the_block_items(context: Context):
81+
actual = [type(item).__name__ for item in context.footer.iter_inner_content()]
82+
expected = ["Paragraph", "Table", "Paragraph"]
83+
assert actual == expected, f"expected: {expected}, got: {actual}"
84+
85+
86+
@then("header.iter_inner_content() produces the block-items in document order")
87+
def then_header_iter_inner_content_produces_the_block_items(context: Context):
88+
actual = [type(item).__name__ for item in context.header.iter_inner_content()]
89+
expected = ["Table", "Paragraph"]
90+
assert actual == expected, f"expected: {expected}, got: {actual}"
91+
92+
4393
@then("I can access the table")
4494
def then_can_access_table(context: Context):
4595
table = context.document.tables[-1]
Binary file not shown.

0 commit comments

Comments
 (0)