Skip to content

Commit f1ca510

Browse files
committed
hdr: add BaseStoryPart._document_part
1 parent 004ac14 commit f1ca510

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

docx/parts/story.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ def get_style_id(self, style_or_name, style_type):
2828
@lazyproperty
2929
def _document_part(self):
3030
"""|DocumentPart| object for this package."""
31-
raise NotImplementedError
31+
return self.package.main_document_part

tests/parts/test_story.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88

99
from docx.enum.style import WD_STYLE_TYPE
10+
from docx.package import Package
1011
from docx.parts.document import DocumentPart
1112
from docx.parts.story import BaseStoryPart
1213
from docx.styles.style import BaseStyle
@@ -29,6 +30,14 @@ def it_can_get_a_style_id_by_style_or_name_and_type(
2930
document_part_.get_style_id.assert_called_once_with(style_, style_type)
3031
assert style_id == "BodyText"
3132

33+
def it_knows_the_main_document_part_to_help(self, package_, document_part_):
34+
package_.main_document_part = document_part_
35+
story_part = BaseStoryPart(None, None, None, package_)
36+
37+
document_part = story_part._document_part
38+
39+
assert document_part is document_part_
40+
3241
# fixture components ---------------------------------------------
3342

3443
@pytest.fixture
@@ -39,6 +48,10 @@ def document_part_(self, request):
3948
def _document_part_prop_(self, request):
4049
return property_mock(request, BaseStoryPart, "_document_part")
4150

51+
@pytest.fixture
52+
def package_(self, request):
53+
return instance_mock(request, Package)
54+
4255
@pytest.fixture
4356
def style_(self, request):
4457
return instance_mock(request, BaseStyle)

0 commit comments

Comments
 (0)