Skip to content

Commit 10055d2

Browse files
author
Steve Canny
committed
acpt: add txt-add-break.feature
1 parent c57765b commit 10055d2

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

features/steps/text.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Step implementations for text-related features
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
from behave import given, then, when
10+
11+
from docx import Document
12+
13+
14+
# given ===================================================
15+
16+
@given('a run')
17+
def given_a_run(context):
18+
p = Document().body.paragraphs[0]
19+
context.run = p.add_run()
20+
21+
22+
# when ====================================================
23+
24+
@when('I add a line break')
25+
def when_add_line_break(context):
26+
run = context.run
27+
run.add_break()
28+
29+
30+
# then =====================================================
31+
32+
@then('the last item in the run is a break')
33+
def then_last_item_in_run_is_a_break(context):
34+
run = context.run
35+
context.last_child = run._r[-1]
36+
expected_tag = (
37+
'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}br'
38+
)
39+
assert context.last_child.tag == expected_tag
40+
41+
42+
@then('it is a line break')
43+
def then_type_is_line_break(context):
44+
attrib = context.last_child.attrib
45+
assert attrib == {}
46+
47+
48+
@then('it is a page break')
49+
def then_type_is_page_break(context):
50+
attrib = context.last_child.attrib
51+
assert attrib == {'type': 'page'}
52+
53+
54+
@then('it is a column break')
55+
def then_type_is_column_break(context):
56+
attrib = context.last_child.attrib
57+
assert attrib == {'type': 'column'}

features/txt-add-break.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Feature: Add a line, page, or column break
2+
In order to control the flow of text in a document
3+
As an python-docx developer
4+
I need the ability to add a line, page, or column break
5+
6+
@wip
7+
Scenario: Add a line break
8+
Given a run
9+
When I add a line break
10+
Then the last item in the run is a break
11+
And it is a line break
12+
13+
@wip
14+
Scenario: Add a page break
15+
Given a run
16+
When I add a page break
17+
Then the last item in the run is a break
18+
And it is a page break
19+
20+
@wip
21+
Scenario: Add a column break
22+
Given a run
23+
When I add a column break
24+
Then the last item in the run is a break
25+
And it is a column break

0 commit comments

Comments
 (0)