Skip to content

Commit c6befdc

Browse files
author
Steve Canny
committed
acpt: add tbl-add-row-or-col.feature
1 parent fe4b7b8 commit c6befdc

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

features/steps/table.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
# given ===================================================
2020

21+
@given('a 2 x 2 table')
22+
def given_a_2x2_table(context):
23+
context.table_ = Document().add_table(rows=2, cols=2)
24+
25+
2126
@given('a column cell collection having two cells')
2227
def given_a_column_cell_collection_having_two_cells(context):
2328
docx_path = test_docx('blk-containing-table')
@@ -48,7 +53,7 @@ def given_a_row_collection_having_two_rows(context):
4853

4954
@given('a table')
5055
def given_a_table(context):
51-
context.table_ = Document().body.add_table(rows=2, cols=2)
56+
context.table_ = Document().add_table(rows=2, cols=2)
5257

5358

5459
@given('a table having an applied style')
@@ -90,6 +95,18 @@ def given_a_table_row_having_two_cells(context):
9095

9196
# when =====================================================
9297

98+
@when('I add a column to the table')
99+
def when_add_column_to_table(context):
100+
table = context.table_
101+
context.column = table.add_column()
102+
103+
104+
@when('I add a row to the table')
105+
def when_add_row_to_table(context):
106+
table = context.table_
107+
context.row = table.add_row()
108+
109+
93110
@when('I apply a style to the table')
94111
def when_apply_style_to_table(context):
95112
table = context.table_
@@ -240,8 +257,32 @@ def then_len_of_row_collection_is_2(context):
240257
assert len(rows) == 2
241258

242259

260+
@then('the new column has 2 cells')
261+
def then_new_column_has_2_cells(context):
262+
assert len(context.column.cells) == 2
263+
264+
265+
@then('the new row has 2 cells')
266+
def then_new_row_has_2_cells(context):
267+
assert len(context.row.cells) == 2
268+
269+
243270
@then('the table style matches the name I applied')
244271
def then_table_style_matches_name_applied(context):
245272
table = context.table_
246273
tmpl = "table.style doesn't match, got '%s'"
247274
assert table.style == 'LightShading-Accent1', tmpl % table.style
275+
276+
277+
@then('the table has {count} columns')
278+
def then_table_has_count_columns(context, count):
279+
column_count = int(count)
280+
columns = context.table_.columns
281+
assert len(columns) == column_count
282+
283+
284+
@then('the table has {count} rows')
285+
def then_table_has_count_rows(context, count):
286+
row_count = int(count)
287+
rows = context.table_.rows
288+
assert len(rows) == row_count
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: Add a row or column to a table
2+
In order to extend an existing table
3+
As an python-docx developer
4+
I need methods to add a row or column
5+
6+
@wip
7+
Scenario: Add a row to a table
8+
Given a 2 x 2 table
9+
When I add a row to the table
10+
Then the table has 3 rows
11+
And the new row has 2 cells
12+
13+
@wip
14+
Scenario: Add a column to a table
15+
Given a 2 x 2 table
16+
When I add a column to the table
17+
Then the table has 3 columns
18+
And the new column has 2 cells

0 commit comments

Comments
 (0)