Skip to content

Commit ec057f3

Browse files
author
Steve Canny
committed
acpt: add api-add-page-break.feature
1 parent 086f219 commit ec057f3

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docx/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class Run(object):
6060
"""
6161
Proxy object wrapping ``<w:r>`` element.
6262
"""
63-
def __init__(self, r_elm):
63+
def __init__(self, r):
6464
super(Run, self).__init__()
65-
self._r = r_elm
65+
self._r = r
6666

6767
def add_break(self, break_type=WD_BREAK.LINE):
6868
"""
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Add a page break
2+
In order to force a page break at a particular location
3+
As a programmer using the basic python-docx API
4+
I need a method that adds a hard page break on its own paragraph
5+
6+
@wip
7+
Scenario: Add a hard page break paragraph
8+
Given a document
9+
When I add a page break to the document
10+
Then the last paragraph contains only a page break

features/steps/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def when_add_heading_specifying_only_its_text(context):
2727
document.add_heading(context.heading_text)
2828

2929

30+
@when('I add a page break to the document')
31+
def when_add_page_break_to_document(context):
32+
document = context.document
33+
document.add_page_break()
34+
35+
3036
@when('I add a paragraph specifying its style')
3137
def when_add_paragraph_specifying_style(context):
3238
document = context.document
@@ -80,6 +86,15 @@ def when_add_picture_specifying_only_image_file(context):
8086

8187
# then =====================================================
8288

89+
@then('the last paragraph contains only a page break')
90+
def then_last_paragraph_contains_only_a_page_break(context):
91+
document = context.document
92+
p = document.paragraphs[-1]
93+
assert len(p.runs) == 1
94+
assert len(p.runs[0]) == 1
95+
assert p.runs[0]._r[0].type == 'page'
96+
97+
8398
@then('the last paragraph contains the heading text')
8499
def then_last_p_contains_heading_text(context):
85100
document = context.document

0 commit comments

Comments
 (0)