Skip to content

Commit 11efbb7

Browse files
author
Steve Canny
committed
style: add BaseStyle.builtin
1 parent ade2ff4 commit 11efbb7

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docx/styles/style.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ class BaseStyle(ElementProxy):
3535

3636
__slots__ = ()
3737

38+
@property
39+
def builtin(self):
40+
"""
41+
Boolean indicating whether this style is a built-in style. False
42+
indicates it is a custom (user-defined) style.
43+
"""
44+
return not self._element.customStyle
45+
3846
@property
3947
def name(self):
4048
"""

features/sty-add-style.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Feature: Add a style
44
I need a way to add a new style
55

66

7-
@wip
87
Scenario Outline: Add a style
98
Given a document having known styles
109
When I call add_style('<name>', <type>, builtin=<builtin>)

tests/styles/test_style.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,22 @@ def it_can_change_its_name(self, name_set_fixture):
117117
style.name = new_value
118118
assert style._element.xml == expected_xml
119119

120+
def it_knows_whether_its_a_builtin_style(self, builtin_get_fixture):
121+
style, expected_value = builtin_get_fixture
122+
assert style.builtin is expected_value
123+
120124
# fixture --------------------------------------------------------
121125

126+
@pytest.fixture(params=[
127+
('w:style', True),
128+
('w:style{w:customStyle=0}', True),
129+
('w:style{w:customStyle=1}', False),
130+
])
131+
def builtin_get_fixture(self, request):
132+
style_cxml, expected_value = request.param
133+
style = BaseStyle(element(style_cxml))
134+
return style, expected_value
135+
122136
@pytest.fixture(params=[
123137
('w:style', None),
124138
('w:style{w:styleId=Foobar}', 'Foobar'),

0 commit comments

Comments
 (0)