Skip to content

Commit 7b40ab3

Browse files
author
Steve Canny
committed
acpt: add run-enum-props.feature
Add scenario outline to test Run.underline getter at API level.
1 parent 599b9c9 commit 7b40ab3

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

docx/enum/text.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,28 @@ class WD_BREAK_TYPE(object):
2525
TEXT_WRAPPING = 11
2626

2727
WD_BREAK = WD_BREAK_TYPE
28+
29+
30+
class WD_UNDERLINE(object):
31+
"""
32+
Corresponds to WdUnderline enumeration
33+
http://msdn.microsoft.com/en-us/library/office/ff822388.aspx
34+
"""
35+
NONE = 0
36+
SINGLE = 1
37+
WORDS = 2
38+
DOUBLE = 3
39+
DOTTED = 4
40+
THICK = 6
41+
DASH = 7
42+
DOT_DASH = 9
43+
DOT_DOT_DASH = 10
44+
WAVY = 11
45+
DOTTED_HEAVY = 20
46+
DASH_HEAVY = 23
47+
DOT_DASH_HEAVY = 25
48+
DOT_DOT_DASH_HEAVY = 26
49+
WAVY_HEAVY = 27
50+
DASH_LONG = 39
51+
WAVY_DOUBLE = 43
52+
DASH_LONG_HEAVY = 55

features/run-enum-props.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Query or apply enumerated run property
2+
In order to query or change an enumerated font property of a word or phrase
3+
As a python-docx developer
4+
I need a way to query and set the enumerated properties on a run
5+
6+
7+
@wip
8+
Scenario Outline: Get underline value of a run
9+
Given a run having <underline-type> underline
10+
Then the run underline property value is <underline-value>
11+
12+
Examples: underline property values
13+
| underline-type | underline-value |
14+
| inherited | None |
15+
| no | False |
16+
| single | True |
17+
| double | WD_UNDERLINE.DOUBLE |
14.3 KB
Binary file not shown.

features/steps/text.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from behave import given, then, when
1010

1111
from docx import Document
12-
from docx.enum.text import WD_BREAK
12+
from docx.enum.text import WD_BREAK, WD_UNDERLINE
1313
from docx.oxml.shared import qn
1414

1515
from .helpers import test_docx, test_text
@@ -30,6 +30,15 @@ def given_a_run_having_bool_prop_set_on(context, bool_prop_name):
3030
context.run = run
3131

3232

33+
@given('a run having {underline_type} underline')
34+
def given_a_run_having_underline_type(context, underline_type):
35+
run_idx = {
36+
'inherited': 0, 'no': 1, 'single': 2, 'double': 3
37+
}[underline_type]
38+
document = Document(test_docx('run-enumerated-props'))
39+
context.run = document.paragraphs[0].runs[run_idx]
40+
41+
3342
@given('a run having style {char_style}')
3443
def given_a_run_having_style_char_style(context, char_style):
3544
run_idx = {
@@ -137,6 +146,15 @@ def then_the_run_contains_the_text_I_specified(context):
137146
assert context.run.text == test_text
138147

139148

149+
@then('the run underline property value is {underline_value}')
150+
def then_the_run_underline_property_value_is(context, underline_value):
151+
expected_value = {
152+
'None': None, 'False': False, 'True': True,
153+
'WD_UNDERLINE.DOUBLE': WD_UNDERLINE.DOUBLE
154+
}[underline_value]
155+
assert context.run.underline == expected_value
156+
157+
140158
@then('the style of the run is {char_style}')
141159
def then_the_style_of_the_run_is_char_style(context, char_style):
142160
expected_value = {

0 commit comments

Comments
 (0)