Skip to content

Commit a9608c8

Browse files
author
Steve Canny
committed
acpt: add scenario for Document.tables
* Improve analogous step for Document.paragraphs
1 parent ac61bf6 commit a9608c8

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

features/doc-access-collections.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ Feature: Access document collections
2222
Scenario: Access the styles collection of a document
2323
Given a document having styles
2424
Then document.styles is a Styles object
25+
26+
27+
Scenario: Access the tables collection of a document
28+
Given a document having three tables
29+
Then document.tables is a list containing three tables

features/steps/document.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from docx.section import Sections
1616
from docx.styles.styles import Styles
1717
from docx.table import Table
18+
from docx.text.paragraph import Paragraph
1819

1920
from helpers import test_docx, test_file
2021

@@ -41,6 +42,11 @@ def given_a_document_having_styles(context):
4142
context.document = Document(test_docx('sty-having-styles-part'))
4243

4344

45+
@given('a document having three tables')
46+
def given_a_document_having_three_tables(context):
47+
context.document = Document(test_docx('tbl-having-tables'))
48+
49+
4450
@given('a single-section document having portrait layout')
4551
def given_a_single_section_document_having_portrait_layout(context):
4652
context.document = Document(test_docx('doc-add-section'))
@@ -164,6 +170,8 @@ def then_document_paragraphs_is_a_list_containing_three_paragraphs(context):
164170
paragraphs = document.paragraphs
165171
assert isinstance(paragraphs, list)
166172
assert len(paragraphs) == 3
173+
for paragraph in paragraphs:
174+
assert isinstance(paragraph, Paragraph)
167175

168176

169177
@then('document.sections is a Sections object')
@@ -179,6 +187,16 @@ def then_document_styles_is_a_Styles_object(context):
179187
assert isinstance(styles, Styles)
180188

181189

190+
@then('document.tables is a list containing three tables')
191+
def then_document_tables_is_a_list_containing_three_tables(context):
192+
document = context.document
193+
tables = document.tables
194+
assert isinstance(tables, list)
195+
assert len(tables) == 3
196+
for table in tables:
197+
assert isinstance(table, Table)
198+
199+
182200
@then('the document contains a 2 x 2 table')
183201
def then_document_contains_2x2_table(context):
184202
document = context.document
31.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)