Skip to content

Commit 37788b0

Browse files
author
Steve Canny
committed
style: add _ParagraphStyle.paragraph_format
1 parent 29b954a commit 37788b0

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

docx/styles/style.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from ..enum.style import WD_STYLE_TYPE
1212
from ..shared import ElementProxy
13+
from ..text.paragraph import ParagraphFormat
1314
from ..text.run import Font
1415

1516

@@ -151,6 +152,14 @@ class _ParagraphStyle(_CharacterStyle):
151152

152153
__slots__ = ()
153154

155+
@property
156+
def paragraph_format(self):
157+
"""
158+
The |ParagraphFormat| object providing access to the paragraph
159+
properties for this style.
160+
"""
161+
return ParagraphFormat(self._element)
162+
154163

155164
class _TableStyle(_ParagraphStyle):
156165
"""

features/sty-access-parfmt.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Feature: Access style paragraph format
44
I need access to the paragraph format of a style
55

66

7-
@wip
87
Scenario Outline: Get style paragraph format
98
Given a style of type <style-type>
109
Then style.paragraph_format is the ParagraphFormat object for the style

tests/styles/test_style.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
BaseStyle, _CharacterStyle, _ParagraphStyle, _NumberingStyle,
1616
StyleFactory, _TableStyle
1717
)
18+
from docx.text.paragraph import ParagraphFormat
1819
from docx.text.run import Font
1920

2021
from ..unitutil.cxml import element, xml
@@ -286,3 +287,32 @@ def style_(self, request):
286287
@pytest.fixture
287288
def StyleFactory_(self, request):
288289
return function_mock(request, 'docx.styles.style.StyleFactory')
290+
291+
292+
class Describe_ParagraphStyle(object):
293+
294+
def it_provides_access_to_its_paragraph_format(self, parfmt_fixture):
295+
style, ParagraphFormat_, paragraph_format_ = parfmt_fixture
296+
paragraph_format = style.paragraph_format
297+
ParagraphFormat_.assert_called_once_with(style._element)
298+
assert paragraph_format is paragraph_format_
299+
300+
# fixtures -------------------------------------------------------
301+
302+
@pytest.fixture
303+
def parfmt_fixture(self, ParagraphFormat_, paragraph_format_):
304+
style = _ParagraphStyle(element('w:style'))
305+
return style, ParagraphFormat_, paragraph_format_
306+
307+
# fixture components ---------------------------------------------
308+
309+
@pytest.fixture
310+
def ParagraphFormat_(self, request, paragraph_format_):
311+
return class_mock(
312+
request, 'docx.styles.style.ParagraphFormat',
313+
return_value=paragraph_format_
314+
)
315+
316+
@pytest.fixture
317+
def paragraph_format_(self, request):
318+
return instance_mock(request, ParagraphFormat)

0 commit comments

Comments
 (0)