Skip to content

Commit ff5e5c2

Browse files
DKWoodsSteve Canny
authored andcommitted
acpt: add scenarios for TabStop property getters
1 parent e5233fd commit ff5e5c2

File tree

7 files changed

+223
-1
lines changed

7 files changed

+223
-1
lines changed

docs/api/enum/WdTabAlignment.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. _WdTabAlignment:
2+
3+
``WD_TAB_ALIGNMENT``
4+
====================
5+
6+
Specifies the tab stop alignment to apply.
7+
8+
----
9+
10+
LEFT
11+
Left-aligned.
12+
13+
CENTER
14+
Center-aligned.
15+
16+
RIGHT
17+
Right-aligned.
18+
19+
DECIMAL
20+
Decimal-aligned.
21+
22+
BAR
23+
Bar-aligned.
24+
25+
LIST
26+
List-aligned. (deprecated)
27+
28+
CLEAR
29+
Clear an inherited tab stop.
30+
31+
END
32+
Right-aligned. (deprecated)
33+
34+
NUM
35+
Left-aligned. (deprecated)
36+
37+
START
38+
Left-aligned. (deprecated)

docs/api/enum/WdTabLeader.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _WdTabLeader:
2+
3+
``WD_TAB_LEADER``
4+
=================
5+
6+
Specifies the character to use as the leader with formatted tabs.
7+
8+
----
9+
10+
SPACES
11+
Spaces. Default.
12+
13+
DOTS
14+
Dots.
15+
16+
DASHES
17+
Dashes.
18+
19+
LINES
20+
Double lines.
21+
22+
HEAVY
23+
A heavy line.
24+
25+
MIDDLE_DOT
26+
A vertically-centered dot.

docs/api/enum/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ can be found here:
1515
WdColorIndex
1616
WdLineSpacing
1717
WdOrientation
18+
WdRowAlignment
1819
WdSectionStart
1920
WdStyleType
20-
WdRowAlignment
21+
WdTabAlignment
22+
WdTabLeader
2123
WdTableDirection
2224
WdUnderline

docx/enum/text.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,80 @@ class WD_LINE_SPACING(XmlEnumeration):
195195
)
196196

197197

198+
class WD_TAB_ALIGNMENT(XmlEnumeration):
199+
"""
200+
Specifies the tab stop alignment to apply.
201+
"""
202+
203+
__ms_name__ = 'WdTabAlignment'
204+
205+
__url__ = 'https://msdn.microsoft.com/EN-US/library/office/ff195609.aspx'
206+
207+
__members__ = (
208+
XmlMappedEnumMember(
209+
'LEFT', 0, 'left', 'Left-aligned.'
210+
),
211+
XmlMappedEnumMember(
212+
'CENTER', 1, 'center', 'Center-aligned.'
213+
),
214+
XmlMappedEnumMember(
215+
'RIGHT', 2, 'right', 'Right-aligned.'
216+
),
217+
XmlMappedEnumMember(
218+
'DECIMAL', 3, 'decimal', 'Decimal-aligned.'
219+
),
220+
XmlMappedEnumMember(
221+
'BAR', 4, 'bar', 'Bar-aligned.'
222+
),
223+
XmlMappedEnumMember(
224+
'LIST', 6, 'list', 'List-aligned. (deprecated)'
225+
),
226+
XmlMappedEnumMember(
227+
'CLEAR', 101, 'clear', 'Clear an inherited tab stop.'
228+
),
229+
XmlMappedEnumMember(
230+
'END', 102, 'end', 'Right-aligned. (deprecated)'
231+
),
232+
XmlMappedEnumMember(
233+
'NUM', 103, 'num', 'Left-aligned. (deprecated)'
234+
),
235+
XmlMappedEnumMember(
236+
'START', 104, 'start', 'Left-aligned. (deprecated)'
237+
),
238+
)
239+
240+
241+
class WD_TAB_LEADER(XmlEnumeration):
242+
"""
243+
Specifies the character to use as the leader with formatted tabs.
244+
"""
245+
246+
__ms_name__ = 'WdTabLeader'
247+
248+
__url__ = 'https://msdn.microsoft.com/en-us/library/office/ff845050.aspx'
249+
250+
__members__ = (
251+
XmlMappedEnumMember(
252+
'SPACES', 0, 'none', 'Spaces. Default.'
253+
),
254+
XmlMappedEnumMember(
255+
'DOTS', 1, 'dot', 'Dots.'
256+
),
257+
XmlMappedEnumMember(
258+
'DASHES', 2, 'hyphen', 'Dashes.'
259+
),
260+
XmlMappedEnumMember(
261+
'LINES', 3, 'underscore', 'Double lines.'
262+
),
263+
XmlMappedEnumMember(
264+
'HEAVY', 4, 'heavy', 'A heavy line.'
265+
),
266+
XmlMappedEnumMember(
267+
'MIDDLE_DOT', 5, 'middleDot', 'A vertically-centered dot.'
268+
),
269+
)
270+
271+
198272
class WD_UNDERLINE(XmlEnumeration):
199273
"""
200274
Specifies the style of underline applied to a run of characters.

features/steps/tabstops.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from behave import given, then
88

99
from docx import Document
10+
from docx.enum.text import WD_TAB_ALIGNMENT, WD_TAB_LEADER
1011
from docx.text.tabstops import TabStop
1112

1213
from helpers import test_docx
@@ -22,6 +23,30 @@ def given_a_tab_stops_having_count_tab_stops(context, count):
2223
context.tab_stops = paragraph_format.tab_stops
2324

2425

26+
@given('a tab stop 0.5 inches {in_or_out} from the paragraph left edge')
27+
def given_a_tab_stop_inches_from_paragraph_left_edge(context, in_or_out):
28+
tab_idx = {'out': 0, 'in': 1}[in_or_out]
29+
document = Document(test_docx('tab-stops'))
30+
paragraph_format = document.paragraphs[2].paragraph_format
31+
context.tab_stop = paragraph_format.tab_stops[tab_idx]
32+
33+
34+
@given('a tab stop having {alignment} alignment')
35+
def given_a_tab_stop_having_alignment_alignment(context, alignment):
36+
tab_idx = {'LEFT': 0, 'CENTER': 1, 'RIGHT': 2}[alignment]
37+
document = Document(test_docx('tab-stops'))
38+
paragraph_format = document.paragraphs[1].paragraph_format
39+
context.tab_stop = paragraph_format.tab_stops[tab_idx]
40+
41+
42+
@given('a tab stop having {leader} leader')
43+
def given_a_tab_stop_having_leader_leader(context, leader):
44+
tab_idx = {'no specified': 0, 'a dotted': 2}[leader]
45+
document = Document(test_docx('tab-stops'))
46+
paragraph_format = document.paragraphs[1].paragraph_format
47+
context.tab_stop = paragraph_format.tab_stops[tab_idx]
48+
49+
2550
# then =====================================================
2651

2752
@then('I can access a tab stop by index')
@@ -43,3 +68,23 @@ def then_I_can_iterate_the_TabStops_object(context):
4368
def then_len_tab_stops_is_count(context, count):
4469
tab_stops = context.tab_stops
4570
assert len(tab_stops) == int(count)
71+
72+
73+
@then('tab_stop.alignment is {alignment}')
74+
def then_tab_stop_alignment_is_alignment(context, alignment):
75+
expected_value = getattr(WD_TAB_ALIGNMENT, alignment)
76+
tab_stop = context.tab_stop
77+
assert tab_stop.alignment == expected_value
78+
79+
80+
@then('tab_stop.leader is {leader}')
81+
def then_tab_stop_leader_is_leader(context, leader):
82+
expected_value = getattr(WD_TAB_LEADER, leader)
83+
tab_stop = context.tab_stop
84+
assert tab_stop.leader == expected_value
85+
86+
87+
@then('tab_stop.position is {position}')
88+
def then_tab_stop_position_is_position(context, position):
89+
tab_stop = context.tab_stop
90+
assert tab_stop.position == int(position)
342 Bytes
Binary file not shown.

features/tab-tabstop-props.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: Tab stop properties
2+
To change the properties of an individual tab stop
3+
As a developer using python-docx
4+
I need a set of read/write properties on TabStop
5+
6+
7+
@wip
8+
Scenario Outline: Get TabStop.position
9+
Given a tab stop 0.5 inches <in-or-out> from the paragraph left edge
10+
Then tab_stop.position is <position>
11+
12+
Examples: tab stop positions
13+
| in-or-out | position |
14+
| in | 457200 |
15+
| out | -457200 |
16+
17+
18+
@wip
19+
Scenario Outline: Get TabStop.alignment
20+
Given a tab stop having <alignment> alignment
21+
Then tab_stop.alignment is <alignment>
22+
23+
Examples: tab stop alignments
24+
| alignment |
25+
| LEFT |
26+
| RIGHT |
27+
28+
29+
@wip
30+
Scenario Outline: Get TabStop.leader
31+
Given a tab stop having <leader> leader
32+
Then tab_stop.leader is <value>
33+
34+
Examples: tab stop leaders
35+
| leader | value |
36+
| no specified | SPACES |
37+
| a dotted | DOTS |

0 commit comments

Comments
 (0)