Skip to content

Commit 5ff190a

Browse files
author
Steve Canny
committed
doc: add DocumentPart.core_properties
1 parent e08d95c commit 5ff190a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

docx/parts/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def core_properties(self):
3737
A |CoreProperties| object providing read/write access to the core
3838
properties of this document.
3939
"""
40-
raise NotImplementedError
40+
return self.package.core_properties
4141

4242
@property
4343
def document(self):

tests/parts/test_document.py

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

1111
from docx.opc.constants import RELATIONSHIP_TYPE as RT
12+
from docx.opc.coreprops import CoreProperties
1213
from docx.oxml.parts.document import CT_Body
1314
from docx.oxml.text.run import CT_R
1415
from docx.package import ImageParts, Package
@@ -61,6 +62,11 @@ def it_provides_access_to_the_document_styles(self, styles_fixture):
6162
styles = document_part.styles
6263
assert styles is styles_
6364

65+
def it_provides_access_to_its_core_properties(self, core_props_fixture):
66+
document_part, core_properties_ = core_props_fixture
67+
core_properties = document_part.core_properties
68+
assert core_properties is core_properties_
69+
6470
def it_provides_access_to_the_inline_shapes_in_the_document(
6571
self, inline_shapes_fixture):
6672
document, InlineShapes_, body_elm = inline_shapes_fixture
@@ -132,6 +138,12 @@ def body_fixture(self, _Body_):
132138
document_part = DocumentPart(None, None, document_elm, None)
133139
return document_part, _Body_, body_elm
134140

141+
@pytest.fixture
142+
def core_props_fixture(self, package_, core_properties_):
143+
document_part = DocumentPart(None, None, None, package_)
144+
package_.core_properties = core_properties_
145+
return document_part, core_properties_
146+
135147
@pytest.fixture
136148
def get_style_fixture(self, styles_prop_, style_):
137149
document_part = DocumentPart(None, None, None, None)
@@ -220,6 +232,10 @@ def _Body_(self, request):
220232
def body_(self, request):
221233
return instance_mock(request, _Body)
222234

235+
@pytest.fixture
236+
def core_properties_(self, request):
237+
return instance_mock(request, CoreProperties)
238+
223239
@pytest.fixture
224240
def document_part_body_(self, request, body_):
225241
return property_mock(

0 commit comments

Comments
 (0)