Skip to content

Commit e130662

Browse files
author
Steve Canny
committed
acpt: migrate doc-add-table.feature
1 parent 7c88a58 commit e130662

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
Feature: Add a table
22
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
3+
As a developer using python-docx
4+
I need a way to add a table
55

66

77
Scenario: Add a table specifying only row and column count
8-
Given a document
8+
Given a blank document
99
When I add a 2 x 2 table specifying only row and column count
1010
Then the document contains a 2 x 2 table
1111
And table.style is styles['Light Shading Accent 1']
1212

1313

1414
Scenario: Add a table specifying style
15-
Given a document
15+
Given a blank document
1616
When I add a 2 x 2 table specifying style 'Table Grid'
1717
Then the document contains a 2 x 2 table
1818
And table.style is styles['Table Grid']

features/steps/api.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import docx
1010

1111
from docx import DocumentNew
12-
from docx.table import Table
1312

1413
from helpers import test_docx
1514

@@ -23,18 +22,6 @@ def given_I_have_python_docx_installed(context):
2322

2423
# when =====================================================
2524

26-
@when('I add a 2 x 2 table specifying only row and column count')
27-
def when_add_2x2_table_specifying_only_row_and_col_count(context):
28-
document = context.document
29-
document.add_table(rows=2, cols=2)
30-
31-
32-
@when('I add a 2 x 2 table specifying style \'{style_name}\'')
33-
def when_add_2x2_table_specifying_style_name(context, style_name):
34-
document = context.document
35-
document.add_table(rows=2, cols=2, style=style_name)
36-
37-
3825
@when('I call docx.Document() with no arguments')
3926
def when_I_call_docx_Document_with_no_arguments(context):
4027
context.document = DocumentNew()
@@ -53,16 +40,6 @@ def then_document_is_a_Document_object(context):
5340
assert isinstance(document, docx.document.Document)
5441

5542

56-
@then('the document contains a 2 x 2 table')
57-
def then_document_contains_2x2_table(context):
58-
document = context.document
59-
table = document.tables[-1]
60-
assert isinstance(table, Table)
61-
assert len(table.rows) == 2
62-
assert len(table.columns) == 2
63-
context.table_ = table
64-
65-
6643
@then('the last paragraph contains the text I specified')
6744
def then_last_p_contains_specified_text(context):
6845
document = context.document

features/steps/document.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from docx.parts.document import Sections
1414
from docx.section import Section
1515
from docx.shared import Inches
16+
from docx.table import Table
1617

1718
from helpers import test_docx, test_file
1819

@@ -44,6 +45,18 @@ def given_a_single_section_document_having_portrait_layout(context):
4445

4546
# when ====================================================
4647

48+
@when('I add a 2 x 2 table specifying only row and column count')
49+
def when_add_2x2_table_specifying_only_row_and_col_count(context):
50+
document = context.document
51+
document.add_table(rows=2, cols=2)
52+
53+
54+
@when('I add a 2 x 2 table specifying style \'{style_name}\'')
55+
def when_add_2x2_table_specifying_style_name(context, style_name):
56+
document = context.document
57+
document.add_table(rows=2, cols=2, style=style_name)
58+
59+
4760
@when('I add a heading specifying level={level}')
4861
def when_add_heading_specifying_level(context, level):
4962
context.document.add_heading(level=int(level))
@@ -158,6 +171,16 @@ def then_I_can_iterate_over_the_sections(context):
158171
assert actual_count == 3
159172

160173

174+
@then('the document contains a 2 x 2 table')
175+
def then_document_contains_2x2_table(context):
176+
document = context.document
177+
table = document.tables[-1]
178+
assert isinstance(table, Table)
179+
assert len(table.rows) == 2
180+
assert len(table.columns) == 2
181+
context.table_ = table
182+
183+
161184
@then('the document has two sections')
162185
def then_the_document_has_two_sections(context):
163186
assert len(context.document.sections) == 2

0 commit comments

Comments
 (0)