Skip to content

Commit 7e10296

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

File tree

9 files changed

+316
-0
lines changed

9 files changed

+316
-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 = {

features/steps/tabs.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
15+
16+
# when ====================================================
17+
18+
@when('I add a tab_stop')
19+
def when_i_add_a_tab_stop(context):
20+
tab_stops = context.paragraph.paragraph_format.tab_stops
21+
tab_stops.add_tab_stop(Inches(1.75))
22+
23+
24+
@when('I delete a tab_stop')
25+
def when_i_delete_a_tab_stop(context):
26+
tab_stops = context.paragraph.paragraph_format.tab_stops
27+
del(tab_stops[1])
28+
29+
30+
@when('I clear the tab_stops')
31+
def when_I_clear_the_tab_stops(context):
32+
tab_stops = context.paragraph.paragraph_format.tab_stops
33+
tab_stops.clear()
34+
35+
36+
# then =====================================================
37+
38+
@then('paragraph_format.tab_stops contain tab_stop objects')
39+
def then_paragraph_format_tab_stops_contain_tab_stop_objects(context):
40+
paragraph = context.paragraph
41+
paragraph_format = paragraph.paragraph_format
42+
tab_stops = paragraph_format.tab_stops
43+
tab_stop = tab_stops[0]
44+
assert isinstance(tab_stop, CT_TabStop)
45+
46+
47+
@then('paragraph_format.tab_stops has {lenval} length')
48+
def then_paragraph_format_tab_stops_has_lenval_length(context, lenval):
49+
tab_stops = context.paragraph.paragraph_format.tab_stops
50+
len_tab_stops = len(tab_stops)
51+
int_len_val = int(lenval)
52+
assert len_tab_stops is int_len_val
53+
54+
55+
@then('I can iterate over the tab_stop elements')
56+
def then_I_can_iterate_over_the_tab_stop_elements(context):
57+
ts = context.paragraph.paragraph_format.tab_stops
58+
tab_stops = [t for t in ts]
59+
assert len(tab_stops) > 0
60+
assert all(isinstance(t, CT_TabStop) for t in tab_stops)
61+
62+
63+
@then('I can access a tab_stop by index')
64+
def then_I_can_access_a_tab_stop_by_index(context):
65+
tab_stops = context.paragraph.paragraph_format.tab_stops
66+
tab_stop = tab_stops[2]
67+
assert isinstance(tab_stop, CT_TabStop)
12.5 KB
Binary file not shown.

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 |

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)