Skip to content

Commit b919cc8

Browse files
committed
acpt: add scenarios for feature/tabstops
1 parent d33255c commit b919cc8

File tree

7 files changed

+170
-0
lines changed

7 files changed

+170
-0
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 alignment of tab stops that can be applied to a paragraph.
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+
START
29+
Left-aligned. (deprecated)
30+
31+
END
32+
Right-aligned. (deprecated)
33+
34+
NUM
35+
Left-aligned! (deprecated)
36+
37+
CLEAR
38+
Clear an inherited tab stop.

docs/api/enum/WdTabLeader.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. _WdTabLeader:
2+
3+
``WD_TAB_LEADER``
4+
=================
5+
6+
Specifies the leading character for tab stops that can be applied to a
7+
paragraph.
8+
9+
----
10+
11+
SPACES
12+
Spaces. Default.
13+
14+
DOTS
15+
Dots.
16+
17+
DASHES
18+
Dashes.
19+
20+
LINES
21+
Double lines.
22+
23+
HEAVY
24+
A heavy line.
25+
26+
MIDDLE_DOT
27+
A middle dot.

docs/api/enum/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ can be found here:
1818
WdSectionStart
1919
WdStyleType
2020
WdRowAlignment
21+
WdTabAlignment
22+
WdTabLeader
2123
WdTableDirection
2224
WdUnderline

docx/enum/text.py

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

197197

198+
class WD_TAB_ALIGNMENT(XmlEnumeration):
199+
"""
200+
Specifies the alignment of tab stops that can be applied to a paragraph.
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 leading character for tab stops that can be applied to a
244+
paragraph.
245+
"""
246+
247+
__ms_name__ = 'WdTabLeader'
248+
249+
__url__ = 'https://msdn.microsoft.com/en-us/library/office/ff845050.aspx'
250+
251+
__members__ = (
252+
XmlMappedEnumMember(
253+
'SPACES', 0, 'none', 'Spaces. Default.'
254+
),
255+
XmlMappedEnumMember(
256+
'DOTS', 1, 'dot', 'Dots.'
257+
),
258+
XmlMappedEnumMember(
259+
'DASHES', 2, 'hyphen', 'Dashes.'
260+
),
261+
XmlMappedEnumMember(
262+
'LINES', 3, 'underscore', 'Double lines.'
263+
),
264+
XmlMappedEnumMember(
265+
'HEAVY', 4, 'heavy', 'A heavy line.'
266+
),
267+
XmlMappedEnumMember(
268+
'MIDDLE_DOT', 5, 'middleDot', 'A middle dot.'
269+
),
270+
)
271+
272+
198273
class WD_UNDERLINE(XmlEnumeration):
199274
"""
200275
Specifies the style of underline applied to a run of characters.

features/steps/parfmt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,23 @@
1313
from docx import Document
1414
from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_LINE_SPACING
1515
from docx.shared import Pt
16+
from docx.oxml.text.parfmt import CT_TabStops
1617

1718
from helpers import test_docx
1819

1920

2021
# given ===================================================
2122

23+
@given('a paragraph having {value} tab_stop elements')
24+
def given_a_paragraph_having_value_tab_stop_elements(context, value):
25+
tabstop_idx = {
26+
'no': 0,
27+
'some': 1
28+
}[value]
29+
document = Document(test_docx('tab-stops'))
30+
context.paragraph = document.paragraphs[tabstop_idx]
31+
32+
2233
@given('a paragraph format having {prop_name} set {setting}')
2334
def given_a_paragraph_format_having_prop_set(context, prop_name, setting):
2435
style_name = {
@@ -139,6 +150,12 @@ def when_I_assign_value_to_paragraph_format_prop(context, value, prop_name):
139150

140151
# then =====================================================
141152

153+
@then('paragraph_format.tab_stops is a CT_TabStops object')
154+
def then_paragraph_format_tab_stops_is_a_ct_tabstops_object(context):
155+
tab_stops = context.paragraph.paragraph_format.tab_stops
156+
assert isinstance(tab_stops, CT_TabStops)
157+
158+
142159
@then('paragraph_format.alignment is {value}')
143160
def then_paragraph_format_alignment_is_value(context, value):
144161
expected_value = {
12.5 KB
Binary file not shown.

features/txt-parfmt-props.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ Feature: Get or set paragraph formatting properties
44
I need a ParagraphFormat object with read/write formatting properties
55

66

7+
@wip
8+
Scenario Outline: Get tab stops object
9+
Given a paragraph having <value> tab_stop elements
10+
Then paragraph_format.tab_stops is a CT_TabStops object
11+
12+
Examples: values for paragraph_format.tab_stop elements
13+
| value |
14+
| no |
15+
| some |
16+
17+
718
Scenario Outline: Get paragraph alignment
819
Given a paragraph format having <align-type> alignment
920
Then paragraph_format.alignment is <value>

0 commit comments

Comments
 (0)