Skip to content

Commit a6b429b

Browse files
author
Steve Canny
committed
style: add BaseStyle.unhide_when_used setter
1 parent 8ea3891 commit a6b429b

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

docx/oxml/styles.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ def unhideWhenUsed_val(self):
154154
return False
155155
return unhideWhenUsed.val
156156

157+
@unhideWhenUsed_val.setter
158+
def unhideWhenUsed_val(self, value):
159+
self._remove_unhideWhenUsed()
160+
if bool(value) is True:
161+
unhideWhenUsed = self._add_unhideWhenUsed()
162+
unhideWhenUsed.val = value
163+
157164

158165
class CT_Styles(BaseOxmlElement):
159166
"""

docx/styles/style.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def unhide_when_used(self):
135135
"""
136136
return self._element.unhideWhenUsed_val
137137

138+
@unhide_when_used.setter
139+
def unhide_when_used(self, value):
140+
self._element.unhideWhenUsed_val = value
141+
138142
@staticmethod
139143
def _translate_special_case_names(name):
140144
"""

features/sty-style-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ Feature: Get and set style properties
108108
| no setting | False |
109109

110110

111-
@wip
112111
Scenario Outline: Set unhide-when-used value
113112
Given a style having unhide-when-used set <setting>
114113
When I assign <new-value> to style.unhide_when_used

tests/styles/test_style.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ def it_knows_whether_its_unhide_when_used(self, unhide_get_fixture):
145145
style, expected_value = unhide_get_fixture
146146
assert style.unhide_when_used == expected_value
147147

148+
def it_can_change_its_unhide_when_used_value(self, unhide_set_fixture):
149+
style, value, expected_xml = unhide_set_fixture
150+
style.unhide_when_used = value
151+
assert style._element.xml == expected_xml
152+
148153
def it_can_delete_itself_from_the_document(self, delete_fixture):
149154
style, styles, expected_xml = delete_fixture
150155
style.delete()
@@ -282,6 +287,26 @@ def unhide_get_fixture(self, request):
282287
style = BaseStyle(element(style_cxml))
283288
return style, expected_value
284289

290+
@pytest.fixture(params=[
291+
('w:style', True,
292+
'w:style/w:unhideWhenUsed'),
293+
('w:style/w:unhideWhenUsed', False,
294+
'w:style'),
295+
('w:style/w:unhideWhenUsed{w:val=0}', True,
296+
'w:style/w:unhideWhenUsed'),
297+
('w:style/w:unhideWhenUsed{w:val=1}', True,
298+
'w:style/w:unhideWhenUsed'),
299+
('w:style/w:unhideWhenUsed{w:val=1}', False,
300+
'w:style'),
301+
('w:style', False,
302+
'w:style'),
303+
])
304+
def unhide_set_fixture(self, request):
305+
style_cxml, value, expected_cxml = request.param
306+
style = BaseStyle(element(style_cxml))
307+
expected_xml = xml(expected_cxml)
308+
return style, value, expected_xml
309+
285310

286311
class Describe_CharacterStyle(object):
287312

0 commit comments

Comments
 (0)