Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a723006

Browse files
DKWoodsSteve Canny
authored andcommitted
acpt: add scenarios for tab stop access
1 parent 9113b49 commit a723006

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@
169169
170170
.. |_TableStyle| replace:: :class:`._TableStyle`
171171
172+
.. |TabStop| replace:: :class:`.TabStop`
173+
174+
.. |TabStops| replace:: :class:`.TabStops`
175+
172176
.. |_Text| replace:: :class:`._Text`
173177
174178
.. |True| replace:: :class:`True`

docx/text/tabstops.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@ class TabStops(ElementProxy):
2424
def __init__(self, element):
2525
super(TabStops, self).__init__(element, None)
2626
self._pPr = element
27+
28+
29+
class TabStop(ElementProxy):
30+
"""
31+
An individual tab stop applying to a paragraph or style. Each of these is
32+
a member of a set held in a |TabStops| object.
33+
"""
34+
35+
__slots__ = ('_tab')
36+
37+
def __init__(self, element):
38+
super(TabStop, self).__init__(element, None)
39+
self._tab = element

features/steps/tabstops.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Step implementations for paragraph-related features
5+
"""
6+
7+
from behave import given, then
8+
9+
from docx import Document
10+
from docx.text.tabstops import TabStop
11+
12+
from helpers import test_docx
13+
14+
15+
# given ===================================================
16+
17+
@given('a tab_stops having {count} tab stops')
18+
def given_a_tab_stops_having_count_tab_stops(context, count):
19+
paragraph_idx = {'0': 0, '3': 1}[count]
20+
document = Document(test_docx('tab-stops'))
21+
paragraph_format = document.paragraphs[paragraph_idx].paragraph_format
22+
context.tab_stops = paragraph_format.tab_stops
23+
24+
25+
# then =====================================================
26+
27+
@then('I can access a tab stop by index')
28+
def then_I_can_access_a_tab_stop_by_index(context):
29+
tab_stops = context.tab_stops
30+
for idx in range(3):
31+
tab_stop = tab_stops[idx]
32+
assert isinstance(tab_stop, TabStop)
33+
34+
35+
@then('I can iterate the TabStops object')
36+
def then_I_can_iterate_the_TabStops_object(context):
37+
items = [ts for ts in context.tab_stops]
38+
assert len(items) == 3
39+
assert all(isinstance(item, TabStop) for item in items)
40+
41+
42+
@then('len(tab_stops) is {count}')
43+
def then_len_tab_stops_is_count(context, count):
44+
tab_stops = context.tab_stops
45+
assert len(tab_stops) == int(count)

features/tab-access-tabs.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Feature: Access TabStop objects
2+
In order to interact with an individual tab stop for a paragraph or style
3+
As a developer using python-docx
4+
I need methods to create, access, and remove a tab stop
5+
6+
7+
@wip
8+
Scenario Outline: TabStops.__len__
9+
Given a tab_stops having <count> tab stops
10+
Then len(tab_stops) is <count>
11+
12+
Examples: tab_stop counts
13+
| count |
14+
| 0 |
15+
| 3 |
16+
17+
18+
@wip
19+
Scenario: Access an existing TabStop object
20+
Given a tab_stops having 3 tab stops
21+
Then I can iterate the TabStops object
22+
And I can access a tab stop by index

0 commit comments

Comments
 (0)