Skip to content

Commit db72fe7

Browse files
committed
hdr: add BaseStoryPart.get_style()
1 parent f1ca510 commit db72fe7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

docx/parts/story.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class BaseStoryPart(XmlPart):
1616
`.add_paragraph()`, `.add_table()` etc.
1717
"""
1818

19+
def get_style(self, style_id, style_type):
20+
"""Return the style in this document matching *style_id*.
21+
22+
Returns the default style for *style_type* if *style_id* is |None| or does not
23+
match a defined style of *style_type*.
24+
"""
25+
return self._document_part.get_style(style_id, style_type)
26+
1927
def get_style_id(self, style_or_name, style_type):
2028
"""Return str style_id for *style_or_name* of *style_type*.
2129

features/hdr-header-footer.feature

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Feature: Header and footer behaviors
3434
And header_2.is_linked_to_previous is True
3535

3636

37-
@wip
3837
Scenario: _Header text accepts style assignment
3938
Given a _Header object with a header definition as header
4039
When I assign "Normal" to header.paragraphs[0].style
@@ -78,7 +77,6 @@ Feature: Header and footer behaviors
7877
And footer_2.is_linked_to_previous is True
7978

8079

81-
@wip
8280
Scenario: _Footer text accepts style assignment
8381
Given a _Footer object with a footer definition as footer
8482
When I assign "Normal" to footer.paragraphs[0].style

tests/parts/test_story.py

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

1818
class DescribeBaseStoryPart(object):
1919

20+
def it_can_get_a_style_by_id_and_type(
21+
self, _document_part_prop_, document_part_, style_
22+
):
23+
style_id = "BodyText"
24+
style_type = WD_STYLE_TYPE.PARAGRAPH
25+
_document_part_prop_.return_value = document_part_
26+
document_part_.get_style.return_value = style_
27+
story_part = BaseStoryPart(None, None, None, None)
28+
29+
style = story_part.get_style(style_id, style_type)
30+
31+
document_part_.get_style.assert_called_once_with(style_id, style_type)
32+
assert style is style_
33+
2034
def it_can_get_a_style_id_by_style_or_name_and_type(
2135
self, _document_part_prop_, document_part_, style_
2236
):

0 commit comments

Comments
 (0)