Skip to content

Commit 58e2151

Browse files
DKWoodsSteve Canny
authored andcommitted
tab: add TabStops.clear_all()
1 parent df04063 commit 58e2151

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docx/text/tabstops.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ def add_tab_stop(self, position, alignment=WD_TAB_ALIGNMENT.LEFT,
7878
tab = tabs.insert_tab_in_order(position, alignment, leader)
7979
return TabStop(tab)
8080

81+
def clear_all(self):
82+
"""
83+
Remove all custom tab stops.
84+
"""
85+
self._pPr._remove_tabs()
86+
8187

8288
class TabStop(ElementProxy):
8389
"""

features/tab-access-tabs.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Feature: Access TabStop objects
3939
And the removed tab stop is no longer present in tab_stops
4040

4141

42-
@wip
4342
Scenario: TabStops.clear_all()
4443
Given a tab_stops having 3 tab stops
4544
When I call tab_stops.clear_all()

tests/text/test_tabstops.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,24 @@ def it_raises_on_del_idx_invalid(self, del_raises_fixture):
175175
del tab_stops[idx]
176176
assert exc.value.args[0] == 'tab index out of range'
177177

178+
def it_can_clear_all_its_tab_stops(self, clear_all_fixture):
179+
tab_stops, expected_xml = clear_all_fixture
180+
tab_stops.clear_all()
181+
assert tab_stops._element.xml == expected_xml
182+
178183
# fixture --------------------------------------------------------
179184

185+
@pytest.fixture(params=[
186+
'w:pPr',
187+
'w:pPr/w:tabs/w:tab{w:pos=42}',
188+
'w:pPr/w:tabs/(w:tab{w:pos=24},w:tab{w:pos=42})',
189+
])
190+
def clear_all_fixture(self, request):
191+
pPr_cxml = request.param
192+
tab_stops = TabStops(element(pPr_cxml))
193+
expected_xml = xml('w:pPr')
194+
return tab_stops, expected_xml
195+
180196
@pytest.fixture(params=[
181197
('w:pPr/w:tabs/w:tab{w:pos=42}', 0,
182198
'w:pPr'),

0 commit comments

Comments
 (0)