Skip to content

Commit

Permalink
xfail: for BlockItemContainer.iter_inner_content()
Browse files Browse the repository at this point in the history
  • Loading branch information
scanny committed Nov 3, 2023
1 parent e315139 commit 3c16691
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
28 changes: 28 additions & 0 deletions features/blk-iter-inner-content.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Iterate paragraphs and tables in document-order
In order to access paragraphs and tables in the same order they appear in the document
As a developer using python-docx
I need the ability to iterate the inner-content of a block-item-container


@wip
Scenario: Document.iter_inner_content()
Given a Document object with paragraphs and tables
Then document.iter_inner_content() produces the block-items in document order


@wip
Scenario: Header.iter_inner_content()
Given a Header object with paragraphs and tables
Then header.iter_inner_content() produces the block-items in document order


@wip
Scenario: Footer.iter_inner_content()
Given a Footer object with paragraphs and tables
Then footer.iter_inner_content() produces the block-items in document order


@wip
Scenario: _Cell.iter_inner_content()
Given a _Cell object with paragraphs and tables
Then cell.iter_inner_content() produces the block-items in document order
50 changes: 50 additions & 0 deletions features/steps/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,33 @@
# given ===================================================


@given("a _Cell object with paragraphs and tables")
def given_a_cell_with_paragraphs_and_tables(context: Context):
context.cell = (
Document(test_docx("blk-paras-and-tables")).tables[1].rows[0].cells[0]
)


@given("a Document object with paragraphs and tables")
def given_a_document_with_paragraphs_and_tables(context: Context):
context.document = Document(test_docx("blk-paras-and-tables"))


@given("a document containing a table")
def given_a_document_containing_a_table(context: Context):
context.document = Document(test_docx("blk-containing-table"))


@given("a Footer object with paragraphs and tables")
def given_a_footer_with_paragraphs_and_tables(context: Context):
context.footer = Document(test_docx("blk-paras-and-tables")).sections[0].footer


@given("a Header object with paragraphs and tables")
def given_a_header_with_paragraphs_and_tables(context: Context):
context.header = Document(test_docx("blk-paras-and-tables")).sections[0].header


@given("a paragraph")
def given_a_paragraph(context: Context):
context.document = Document()
Expand All @@ -40,6 +62,34 @@ def when_add_table(context: Context):
# then =====================================================


@then("cell.iter_inner_content() produces the block-items in document order")
def then_cell_iter_inner_content_produces_the_block_items(context: Context):
actual = [type(item).__name__ for item in context.cell.iter_inner_content()]
expected = ["Paragraph", "Table", "Paragraph"]
assert actual == expected, f"expected: {expected}, got: {actual}"


@then("document.iter_inner_content() produces the block-items in document order")
def then_document_iter_inner_content_produces_the_block_items(context: Context):
actual = [type(item).__name__ for item in context.document.iter_inner_content()]
expected = ["Table", "Paragraph", "Table", "Paragraph", "Table", "Paragraph"]
assert actual == expected, f"expected: {expected}, got: {actual}"


@then("footer.iter_inner_content() produces the block-items in document order")
def then_footer_iter_inner_content_produces_the_block_items(context: Context):
actual = [type(item).__name__ for item in context.footer.iter_inner_content()]
expected = ["Paragraph", "Table", "Paragraph"]
assert actual == expected, f"expected: {expected}, got: {actual}"


@then("header.iter_inner_content() produces the block-items in document order")
def then_header_iter_inner_content_produces_the_block_items(context: Context):
actual = [type(item).__name__ for item in context.header.iter_inner_content()]
expected = ["Table", "Paragraph"]
assert actual == expected, f"expected: {expected}, got: {actual}"


@then("I can access the table")
def then_can_access_table(context: Context):
table = context.document.tables[-1]
Expand Down
Binary file not shown.

0 comments on commit 3c16691

Please sign in to comment.