Skip to content

Commit f615c58

Browse files
author
Steve Canny
committed
acpt: migrate doc-add-heading.feature
1 parent 11394a0 commit f615c58

File tree

4 files changed

+54
-61
lines changed

4 files changed

+54
-61
lines changed

features/api-add-heading.feature

Lines changed: 0 additions & 30 deletions
This file was deleted.

features/doc-add-heading.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Feature: Add a heading paragraph
2+
In order add a heading to a document
3+
As a developer using python-docx
4+
I need a way to add a heading with its text and level in a single step
5+
6+
7+
Scenario: Add a heading specifying only its text
8+
Given a blank document
9+
When I add a heading specifying only its text
10+
Then the style of the last paragraph is 'Heading 1'
11+
And the last paragraph contains the heading text
12+
13+
14+
Scenario Outline: Add a heading specifying level
15+
Given a blank document
16+
When I add a heading specifying level=<level>
17+
Then the style of the last paragraph is '<style>'
18+
19+
Examples: Heading level styles
20+
| level | style |
21+
| 0 | Title |
22+
| 1 | Heading 1 |
23+
| 2 | Heading 2 |
24+
| 5 | Heading 5 |
25+
| 9 | Heading 9 |

features/steps/api.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ def when_add_2x2_table_specifying_style_name(context, style_name):
3636
document.add_table(rows=2, cols=2, style=style_name)
3737

3838

39-
@when('I add a heading specifying level={level_str}')
40-
def when_add_heading_specifying_level(context, level_str):
41-
level = int(level_str)
42-
document = context.document
43-
document.add_heading(level=level)
44-
45-
46-
@when('I add a heading specifying only its text')
47-
def when_add_heading_specifying_only_its_text(context):
48-
document = context.document
49-
context.heading_text = 'Spam vs. Eggs'
50-
document.add_heading(context.heading_text)
51-
52-
5339
@when('I add a page break to the document')
5440
def when_add_page_break_to_document(context):
5541
document = context.document
@@ -124,14 +110,6 @@ def then_last_paragraph_contains_only_a_page_break(context):
124110
assert p.runs[0]._r[0].type == 'page'
125111

126112

127-
@then('the last paragraph contains the heading text')
128-
def then_last_p_contains_heading_text(context):
129-
document = context.document
130-
text = context.heading_text
131-
p = document.paragraphs[-1]
132-
assert p.text == text
133-
134-
135113
@then('the last paragraph contains the text I specified')
136114
def then_last_p_contains_specified_text(context):
137115
document = context.document
@@ -152,12 +130,3 @@ def then_last_p_is_empty_paragraph_added(context):
152130
document = context.document
153131
p = document.paragraphs[-1]
154132
assert p.text == ''
155-
156-
157-
@then('the style of the last paragraph is \'{style_name}\'')
158-
def then_the_style_of_the_last_paragraph_is_style(context, style_name):
159-
document = context.document
160-
paragraph = document.paragraphs[-1]
161-
assert paragraph.style.name == style_name, (
162-
'got %s' % paragraph.style.name
163-
)

features/steps/document.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ def given_a_single_section_document_having_portrait_layout(context):
4343

4444
# when ====================================================
4545

46+
@when('I add a heading specifying level={level}')
47+
def when_add_heading_specifying_level(context, level):
48+
context.document.add_heading(level=int(level))
49+
50+
51+
@when('I add a heading specifying only its text')
52+
def when_add_heading_specifying_only_its_text(context):
53+
document = context.document
54+
context.heading_text = text = 'Spam vs. Eggs'
55+
document.add_heading(text)
56+
57+
4658
@when('I add a paragraph specifying its style as a {kind}')
4759
def when_I_add_a_paragraph_specifying_its_style_as_a(context, kind):
4860
document = context.document
@@ -122,6 +134,14 @@ def then_the_first_section_is_portrait(context):
122134
assert first_section.page_height == expected_height
123135

124136

137+
@then('the last paragraph contains the heading text')
138+
def then_last_p_contains_heading_text(context):
139+
document = context.document
140+
text = context.heading_text
141+
paragraph = document.paragraphs[-1]
142+
assert paragraph.text == text
143+
144+
125145
@then('the length of the section collection is 3')
126146
def then_the_length_of_the_section_collection_is_3(context):
127147
sections = context.document.sections
@@ -137,3 +157,12 @@ def then_the_second_section_is_landscape(context):
137157
assert new_section.orientation == WD_ORIENT.LANDSCAPE
138158
assert new_section.page_width == expected_width
139159
assert new_section.page_height == expected_height
160+
161+
162+
@then('the style of the last paragraph is \'{style_name}\'')
163+
def then_the_style_of_the_last_paragraph_is_style(context, style_name):
164+
document = context.document
165+
paragraph = document.paragraphs[-1]
166+
assert paragraph.style.name == style_name, (
167+
'got %s' % paragraph.style.name
168+
)

0 commit comments

Comments
 (0)