Skip to content

Commit 3fdf8f2

Browse files
committed
acpt: add scenarios for feature/tabstops
1 parent b8e3de8 commit 3fdf8f2

File tree

6 files changed

+296
-0
lines changed

6 files changed

+296
-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/tabs.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Step implementations for paragraph-related features
5+
"""
6+
7+
from behave import then, when
8+
9+
from docx.oxml.text.parfmt import CT_TabStop
10+
from docx.shared import Inches
11+
12+
13+
# given ===================================================
14+
@given('a paragraph having {value} tab_stop elements')
15+
def given_a_paragraph_having_value_tab_stop_elements(context, value):
16+
tabstop_idx = {
17+
'no': 0,
18+
'some': 1
19+
}[value]
20+
document = Document(test_docx('tab-stops'))
21+
context.paragraph = document.paragraphs[tabstop_idx]
22+
23+
24+
# when ====================================================
25+
26+
@when('I add a tab_stop')
27+
def when_i_add_a_tab_stop(context):
28+
tab_stops = context.paragraph.paragraph_format.tab_stops
29+
tab_stops.add_tab_stop(Inches(1.75))
30+
31+
32+
@when('I delete a tab_stop')
33+
def when_i_delete_a_tab_stop(context):
34+
tab_stops = context.paragraph.paragraph_format.tab_stops
35+
del(tab_stops[1])
36+
37+
38+
@when('I clear the tab_stops')
39+
def when_I_clear_the_tab_stops(context):
40+
tab_stops = context.paragraph.paragraph_format.tab_stops
41+
tab_stops.clear()
42+
43+
44+
# then =====================================================
45+
46+
@then('paragraph_format.tab_stops contain tab_stop objects')
47+
def then_paragraph_format_tab_stops_contain_tab_stop_objects(context):
48+
paragraph = context.paragraph
49+
paragraph_format = paragraph.paragraph_format
50+
tab_stops = paragraph_format.tab_stops
51+
tab_stop = tab_stops[0]
52+
assert isinstance(tab_stop, CT_TabStop)
53+
54+
55+
@then('paragraph_format.tab_stops has {lenval} length')
56+
def then_paragraph_format_tab_stops_has_lenval_length(context, lenval):
57+
tab_stops = context.paragraph.paragraph_format.tab_stops
58+
len_tab_stops = len(tab_stops)
59+
int_len_val = int(lenval)
60+
assert len_tab_stops is int_len_val
61+
62+
63+
@then('I can iterate over the tab_stop elements')
64+
def then_I_can_iterate_over_the_tab_stop_elements(context):
65+
ts = context.paragraph.paragraph_format.tab_stops
66+
tab_stops = [t for t in ts]
67+
assert len(tab_stops) > 0
68+
assert all(isinstance(t, CT_TabStop) for t in tab_stops)
69+
70+
71+
@then('I can access a tab_stop by index')
72+
def then_I_can_access_a_tab_stop_by_index(context):
73+
tab_stops = context.paragraph.paragraph_format.tab_stops
74+
tab_stop = tab_stops[2]
75+
assert isinstance(tab_stop, CT_TabStop)

features/tab-access-tabs.feature

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Feature: Get or set TabStops
2+
In order to customize tab stops
3+
As a python-docx developer
4+
I need a TabStops object with read/write tab_stop properties
5+
6+
7+
@wip
8+
Scenario Outline: Get tab_stop objects
9+
Given a paragraph having <value> tab_stop elements
10+
Then paragraph_format.tab_stops contain tab_stop objects
11+
12+
Examples: values for tab_stop elements
13+
| value |
14+
| some |
15+
16+
17+
@wip
18+
Scenario Outline: Count tab stop objects
19+
Given a paragraph having <value> tab_stop elements
20+
Then paragraph_format.tab_stops has <lenval> length
21+
22+
Examples: length values for tab_stop elements
23+
| value | lenval |
24+
| no | 0 |
25+
| some | 3 |
26+
27+
28+
@wip
29+
Scenario Outline: Iterate over tab stop objects
30+
Given a paragraph having <value> tab_stop elements
31+
Then I can iterate over the tab_stop elements
32+
33+
Examples: values for tab_stop elements
34+
| value |
35+
| some |
36+
37+
38+
@wip
39+
Scenario Outline: Access a tab stop by index
40+
Given a paragraph having <value> tab_stop elements
41+
Then I can access a tab_stop by index
42+
43+
Examples: values for tab_stop elements
44+
| value |
45+
| some |
46+
47+
48+
@wip
49+
Scenario Outline: Add a tab stop
50+
Given a paragraph having <value> tab_stop elements
51+
When I add a tab_stop
52+
Then paragraph_format.tab_stops has <lenval> length
53+
54+
Examples: values for tab_stop elements
55+
| value | lenval |
56+
| no | 1 |
57+
| some | 4 |
58+
59+
60+
@wip
61+
Scenario Outline: Delete a tab stop
62+
Given a paragraph having <value> tab_stop elements
63+
When I delete a tab_stop
64+
Then paragraph_format.tab_stops has <lenval> length
65+
66+
Examples: values for tab_stop elements
67+
| value | lenval |
68+
| some | 2 |
69+
70+
71+
@wip
72+
Scenario Outline: Clear tab stops
73+
Given a paragraph having <value> tab_stop elements
74+
When I clear the tab_stops
75+
Then paragraph_format.tab_stops has <lenval> length
76+
77+
Examples: values for tab_stop elements
78+
| value | lenval |
79+
| some | 0 |

0 commit comments

Comments
 (0)