Skip to content

Commit d096821

Browse files
author
Steve Canny
committed
acpt: elaborate Document.add_paragraph() scenario
Add case for specifying style as style object.
1 parent f945031 commit d096821

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

features/api-add-paragraph.feature

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@ Feature: Add a paragraph with optional text and style
33
As a programmer using the basic python-docx API
44
I want to add a styled paragraph of text in a single step
55

6+
67
Scenario: Add an empty paragraph
78
Given a document
89
When I add a paragraph without specifying text or style
910
Then the last paragraph is the empty paragraph I added
1011

12+
1113
Scenario: Add a paragraph specifying its text
1214
Given a document
1315
When I add a paragraph specifying its text
1416
Then the last paragraph contains the text I specified
1517

16-
Scenario: Add a paragraph specifying its style
18+
19+
@wip
20+
Scenario Outline: Add a paragraph specifying its style
1721
Given a document
18-
When I add a paragraph specifying its style
22+
When I add a paragraph specifying its style as a <style-spec>
1923
Then the last paragraph has the style I specified
24+
25+
Examples: ways of specifying a style
26+
| style-spec |
27+
| style object |
28+
| style name |

features/steps/api.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ def when_add_page_break_to_document(context):
4646
document.add_page_break()
4747

4848

49-
@when('I add a paragraph specifying its style')
50-
def when_add_paragraph_specifying_style(context):
49+
@when('I add a paragraph specifying its style as a {kind}')
50+
def when_I_add_a_paragraph_specifying_its_style_as_a(context, kind):
5151
document = context.document
52-
context.paragraph_style = 'barfoo'
53-
document.add_paragraph(style=context.paragraph_style)
52+
style = context.style = document.styles['Heading 1']
53+
style_spec = {
54+
'style object': style,
55+
'style name': 'Heading 1',
56+
}[kind]
57+
document.add_paragraph(style=style_spec)
5458

5559

5660
@when('I add a paragraph specifying its text')
@@ -135,11 +139,10 @@ def then_last_p_contains_specified_text(context):
135139

136140

137141
@then('the last paragraph has the style I specified')
138-
def then_last_p_has_specified_style(context):
139-
document = context.document
140-
style = context.paragraph_style
141-
p = document.paragraphs[-1]
142-
assert p.style == style
142+
def then_the_last_paragraph_has_the_style_I_specified(context):
143+
document, expected_style = context.document, context.style
144+
paragraph = document.paragraphs[-1]
145+
assert paragraph.style == expected_style
143146

144147

145148
@then('the last paragraph is the empty paragraph I added')

0 commit comments

Comments
 (0)