Skip to content

Commit 5309b41

Browse files
author
Steve Canny
committed
acpt: groom some existing acceptance tests
* add specific Given for a document having the built-in styles * constrain 'Given a blank document' to not have the built-in styles * revise some steps to make them more concise * extract bool_vals and tri_state_vals to helpers
1 parent 5a012fe commit 5309b41

File tree

7 files changed

+24
-21
lines changed

7 files changed

+24
-21
lines changed

features/doc-add-heading.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Feature: Add a heading paragraph
55

66

77
Scenario: Add a heading specifying only its text
8-
Given a blank document
8+
Given a document having built-in styles
99
When I add a heading specifying only its text
1010
Then the style of the last paragraph is 'Heading 1'
1111
And the last paragraph contains the heading text
1212

1313

1414
Scenario Outline: Add a heading specifying level
15-
Given a blank document
15+
Given a document having built-in styles
1616
When I add a heading specifying level=<level>
1717
Then the style of the last paragraph is '<style>'
1818

features/doc-add-table.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Feature: Add a table
55

66

77
Scenario: Add a table specifying only row and column count
8-
Given a blank document
8+
Given a document having built-in styles
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 blank document
15+
Given a document having built-in styles
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/block.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
@given('a document containing a table')
1818
def given_a_document_containing_a_table(context):
19-
docx_path = test_docx('blk-containing-table')
20-
context.document = Document(docx_path)
19+
context.document = Document(test_docx('blk-containing-table'))
2120

2221

2322
@given('a paragraph')

features/steps/document.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
@given('a blank document')
2626
def given_a_blank_document(context):
27+
context.document = Document(test_docx('doc-word-default-blank'))
28+
29+
30+
@given('a document having built-in styles')
31+
def given_a_document_having_builtin_styles(context):
2732
context.document = Document()
2833

2934

@@ -198,9 +203,8 @@ def then_document_tables_is_a_list_containing_three_tables(context):
198203

199204

200205
@then('the document contains a 2 x 2 table')
201-
def then_document_contains_2x2_table(context):
202-
document = context.document
203-
table = document.tables[-1]
206+
def then_the_document_contains_a_2x2_table(context):
207+
table = context.document.tables[-1]
204208
assert isinstance(table, Table)
205209
assert len(table.rows) == 2
206210
assert len(table.columns) == 2

features/steps/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ def absjoin(*paths):
1616
# scratch output docx file -------------
1717
saved_docx_path = absjoin(scratch_dir, 'test_out.docx')
1818

19+
bool_vals = {
20+
'True': True,
21+
'False': False
22+
}
23+
1924
test_text = 'python-docx was here!'
2025

26+
tri_state_vals = {
27+
'True': True,
28+
'False': False,
29+
'None': None,
30+
}
31+
2132

2233
def test_docx(name):
2334
"""

features/steps/styles.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
from docx.text.font import Font
1414
from docx.text.parfmt import ParagraphFormat
1515

16-
from helpers import test_docx
17-
18-
bool_vals = {
19-
'True': True,
20-
'False': False
21-
}
16+
from helpers import bool_vals, test_docx, tri_state_vals
2217

2318
style_types = {
2419
'WD_STYLE_TYPE.CHARACTER': WD_STYLE_TYPE.CHARACTER,
@@ -27,12 +22,6 @@
2722
'WD_STYLE_TYPE.TABLE': WD_STYLE_TYPE.TABLE,
2823
}
2924

30-
tri_state_vals = {
31-
'True': True,
32-
'False': False,
33-
'None': None,
34-
}
35-
3625

3726
# given ===================================================
3827

Binary file not shown.

0 commit comments

Comments
 (0)