Skip to content

Commit 10c01d1

Browse files
author
Steve Canny
committed
style: add _LatentStyle.delete()
1 parent f3fa3a9 commit 10c01d1

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

docx/oxml/styles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ class CT_LsdException(BaseOxmlElement):
8585
uiPriority = OptionalAttribute('w:uiPriority', ST_DecimalNumber)
8686
unhideWhenUsed = OptionalAttribute('w:unhideWhenUsed', ST_OnOff)
8787

88+
def delete(self):
89+
"""
90+
Remove this `w:lsdException` element from the XML document.
91+
"""
92+
self.getparent().remove(self)
93+
8894
def on_off_prop(self, attr_name):
8995
"""
9096
Return the boolean value of the attribute having *attr_name*, or

docx/styles/latent.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ class _LatentStyle(ElementProxy):
136136

137137
__slots__ = ()
138138

139+
def delete(self):
140+
"""
141+
Remove this latent style definition such that the defaults defined in
142+
the containing |LatentStyles| object provide the effective value for
143+
each of its attributes. Attempting to access any attributes on this
144+
object after calling this method will raise |AttributeError|.
145+
"""
146+
self._element.delete()
147+
self._element = None
148+
139149
@property
140150
def hidden(self):
141151
"""

features/sty-latent-add-del.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Feature: Add or delete a latent style
1111
And latent_styles['Foobar'] is a latent style
1212

1313

14-
@wip
1514
Scenario: Delete a latent style
1615
Given a document having known styles
1716
When I delete a latent style

tests/styles/test_latent.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
class DescribeLatentStyle(object):
1919

20+
def it_can_delete_itself(self, delete_fixture):
21+
latent_style, latent_styles, expected_xml = delete_fixture
22+
latent_style.delete()
23+
assert latent_styles.xml == expected_xml
24+
assert latent_style._element is None
25+
2026
def it_knows_its_name(self, name_get_fixture):
2127
latent_style, expected_value = name_get_fixture
2228
assert latent_style.name == expected_value
@@ -42,6 +48,13 @@ def it_can_change_its_on_off_properties(self, on_off_set_fixture):
4248

4349
# fixtures -------------------------------------------------------
4450

51+
@pytest.fixture
52+
def delete_fixture(self):
53+
latent_styles = element('w:latentStyles/w:lsdException{w:name=Foo}')
54+
latent_style = _LatentStyle(latent_styles[0])
55+
expected_xml = xml('w:latentStyles')
56+
return latent_style, latent_styles, expected_xml
57+
4558
@pytest.fixture(params=[
4659
('w:lsdException{w:name=Foobar}', 'Foobar'),
4760
])

0 commit comments

Comments
 (0)