Skip to content

Commit ebd5e85

Browse files
author
Steve Canny
committed
acpt: add scenario for _Cell.add_table()
1 parent 1ff6d38 commit ebd5e85

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

features/cel-add-table.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: Add a table into a table cell
2+
In order to nest a table within a table cell
3+
As a developer using python-docx
4+
I need a way to add a table to a table cell
5+
6+
7+
@wip
8+
Scenario: Add a table into a table cell
9+
Given a table cell
10+
When I add a 2 x 2 table into the first cell
11+
Then cell.tables[0] is a 2 x 2 table
12+
And the width of each column is 1.5375 inches
13+
And the width of each cell is 1.5375 inches

features/steps/cell.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@
1010

1111
from docx import Document
1212

13+
from helpers import test_docx
14+
1315

1416
# given ===================================================
1517

1618
@given('a table cell')
1719
def given_a_table_cell(context):
18-
table = Document().add_table(rows=2, cols=2)
20+
table = Document(test_docx('tbl-2x2-table')).tables[0]
1921
context.cell = table.cell(0, 0)
2022

2123

2224
# when =====================================================
2325

26+
@when('I add a 2 x 2 table into the first cell')
27+
def when_I_add_a_2x2_table_into_the_first_cell(context):
28+
context.table_ = context.cell.add_table(2, 2)
29+
30+
2431
@when('I assign a string to the cell text attribute')
2532
def when_assign_string_to_cell_text_attribute(context):
2633
cell = context.cell
@@ -31,6 +38,14 @@ def when_assign_string_to_cell_text_attribute(context):
3138

3239
# then =====================================================
3340

41+
@then('cell.tables[0] is a 2 x 2 table')
42+
def then_cell_tables_0_is_a_2x2_table(context):
43+
cell = context.cell
44+
table = cell.tables[0]
45+
assert len(table.rows) == 2
46+
assert len(table.columns) == 2
47+
48+
3449
@then('the cell contains the string I assigned')
3550
def then_cell_contains_string_assigned(context):
3651
cell, expected_text = context.cell, context.expected_text
24.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)