Skip to content

Commit 6855f9a

Browse files
author
Steve Canny
committed
acpt: add api-add-table.feature
1 parent 595cc87 commit 6855f9a

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

features/api-add-table.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: Add a table
2+
In order to include tablular information in a document
3+
As a programmer using the basic python-docx API
4+
I need a method that adds a table at the end of the document
5+
6+
@wip
7+
Scenario: Add a table specifying only row and column count
8+
Given a document
9+
When I add a 2 x 2 table specifying only row and column count
10+
Then the document contains a 2 x 2 table
11+
And the table style is 'LightShading-Accent1'
12+
13+
@wip
14+
Scenario: Add a table specifying style
15+
Given a document
16+
When I add a 2 x 2 table specifying style 'foobar'
17+
Then the document contains a 2 x 2 table
18+
And the table style is 'foobar'

features/steps/api.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@
77
from behave import then, when
88

99
from docx.shared import Inches
10+
from docx.table import Table
1011

1112
from .helpers import test_file_path
1213

1314

1415
# when ====================================================
1516

17+
@when('I add a 2 x 2 table specifying only row and column count')
18+
def when_add_2x2_table_specifying_only_row_and_col_count(context):
19+
document = context.document
20+
document.add_table(rows=2, cols=2)
21+
22+
23+
@when('I add a 2 x 2 table specifying style \'foobar\'')
24+
def when_add_2x2_table_specifying_style_foobar(context):
25+
document = context.document
26+
document.add_table(rows=2, cols=2, style='foobar')
27+
28+
1629
@when('I add a heading specifying level={level_str}')
1730
def when_add_heading_specifying_level(context, level_str):
1831
level = int(level_str)
@@ -86,6 +99,16 @@ def when_add_picture_specifying_only_image_file(context):
8699

87100
# then =====================================================
88101

102+
@then('the document contains a 2 x 2 table')
103+
def then_document_contains_2x2_table(context):
104+
document = context.document
105+
table = document.tables[-1]
106+
assert isinstance(table, Table)
107+
assert len(table.rows) == 2
108+
assert len(table.cols) == 2
109+
context.table = table
110+
111+
89112
@then('the last paragraph contains only a page break')
90113
def then_last_paragraph_contains_only_a_page_break(context):
91114
document = context.document
@@ -162,3 +185,9 @@ def then_style_of_last_paragraph_is_style(context, style):
162185
document = context.document
163186
p = document.paragraphs[-1]
164187
assert p.style == style
188+
189+
190+
@then('the table style is \'{style}\'')
191+
def then_table_style_is_style(context, style):
192+
table = context.table
193+
assert table.style == style

0 commit comments

Comments
 (0)