Skip to content

Commit be56d1d

Browse files
author
Steve Canny
committed
acpt: migrate doc-add-paragraph.feature
1 parent ce2f4cd commit be56d1d

3 files changed

Lines changed: 33 additions & 28 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
Feature: Add a paragraph with optional text and style
22
In order to populate the text of a document
3-
As a programmer using the basic python-docx API
4-
I want to add a styled paragraph of text in a single step
3+
As a developer using python-docx
4+
I need a way to add a styled paragraph of text in a single step
55

66

77
Scenario: Add an empty paragraph
8-
Given a document
8+
Given a blank document
99
When I add a paragraph without specifying text or style
1010
Then the last paragraph is the empty paragraph I added
1111

1212

1313
Scenario: Add a paragraph specifying its text
14-
Given a document
14+
Given a blank document
1515
When I add a paragraph specifying its text
1616
Then the last paragraph contains the text I specified
1717

features/steps/api.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,6 @@ def when_add_page_break_to_document(context):
5656
document.add_page_break()
5757

5858

59-
@when('I add a paragraph specifying its style as a {kind}')
60-
def when_I_add_a_paragraph_specifying_its_style_as_a(context, kind):
61-
document = context.document
62-
style = context.style = document.styles['Heading 1']
63-
style_spec = {
64-
'style object': style,
65-
'style name': 'Heading 1',
66-
}[kind]
67-
document.add_paragraph(style=style_spec)
68-
69-
70-
@when('I add a paragraph specifying its text')
71-
def when_add_paragraph_specifying_text(context):
72-
document = context.document
73-
context.paragraph_text = 'foobar'
74-
document.add_paragraph(context.paragraph_text)
75-
76-
77-
@when('I add a paragraph without specifying text or style')
78-
def when_add_paragraph_without_specifying_text_or_style(context):
79-
document = context.document
80-
document.add_paragraph()
81-
82-
8359
@when('I add a picture specifying 1.75" width and 2.5" height')
8460
def when_add_picture_specifying_width_and_height(context):
8561
document = context.document

features/steps/document.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

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

21+
@given('a blank document')
22+
def given_a_blank_document(context):
23+
context.document = Document()
24+
25+
2126
@given('a document having three sections')
2227
def given_a_document_having_three_sections(context):
2328
context.document = Document(test_docx('doc-access-sections'))
@@ -38,6 +43,30 @@ def given_a_single_section_document_having_portrait_layout(context):
3843

3944
# when ====================================================
4045

46+
@when('I add a paragraph specifying its style as a {kind}')
47+
def when_I_add_a_paragraph_specifying_its_style_as_a(context, kind):
48+
document = context.document
49+
style = context.style = document.styles['Heading 1']
50+
style_spec = {
51+
'style object': style,
52+
'style name': 'Heading 1',
53+
}[kind]
54+
document.add_paragraph(style=style_spec)
55+
56+
57+
@when('I add a paragraph specifying its text')
58+
def when_add_paragraph_specifying_text(context):
59+
document = context.document
60+
context.paragraph_text = 'foobar'
61+
document.add_paragraph(context.paragraph_text)
62+
63+
64+
@when('I add a paragraph without specifying text or style')
65+
def when_add_paragraph_without_specifying_text_or_style(context):
66+
document = context.document
67+
document.add_paragraph()
68+
69+
4170
@when('I add an even-page section to the document')
4271
def when_I_add_an_even_page_section_to_the_document(context):
4372
context.section = context.document.add_section(WD_SECTION.EVEN_PAGE)

0 commit comments

Comments
 (0)