Skip to content

Commit fbc93af

Browse files
author
Steve Canny
committed
style: add _Style.style_id setter
1 parent 4d196dd commit fbc93af

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

docx/styles/style.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def style_id(self):
4242
"""
4343
return self._element.styleId
4444

45+
@style_id.setter
46+
def style_id(self, value):
47+
self._element.styleId = value
48+
4549

4650
class _CharacterStyle(BaseStyle):
4751
"""

features/sty-style-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Feature: Get and set style properties
99
Then style.style_id is the known style id
1010

1111

12-
@wip
1312
Scenario: Set style id
1413
Given a style having a known style id
1514
When I assign a new value to style.style_id

tests/styles/test_style.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
StyleFactory, _TableStyle
1616
)
1717

18-
from ..unitutil.cxml import element
18+
from ..unitutil.cxml import element, xml
1919
from ..unitutil.mock import class_mock, instance_mock
2020

2121

@@ -98,6 +98,11 @@ def it_knows_its_style_id(self, id_get_fixture):
9898
style, expected_value = id_get_fixture
9999
assert style.style_id == expected_value
100100

101+
def it_can_change_its_style_id(self, id_set_fixture):
102+
style, new_value, expected_xml = id_set_fixture
103+
style.style_id = new_value
104+
assert style._element.xml == expected_xml
105+
101106
# fixture --------------------------------------------------------
102107

103108
@pytest.fixture(params=[
@@ -108,3 +113,15 @@ def id_get_fixture(self, request):
108113
style_cxml, expected_value = request.param
109114
style = BaseStyle(element(style_cxml))
110115
return style, expected_value
116+
117+
@pytest.fixture(params=[
118+
('w:style', 'Foo', 'w:style{w:styleId=Foo}'),
119+
('w:style{w:styleId=Foo}', 'Bar', 'w:style{w:styleId=Bar}'),
120+
('w:style{w:styleId=Bar}', None, 'w:style'),
121+
('w:style', None, 'w:style'),
122+
])
123+
def id_set_fixture(self, request):
124+
style_cxml, new_value, expected_style_cxml = request.param
125+
style = BaseStyle(element(style_cxml))
126+
expected_xml = xml(expected_style_cxml)
127+
return style, new_value, expected_xml

0 commit comments

Comments
 (0)