Skip to content

Commit 652fc43

Browse files
author
Steve Canny
committed
doc: add Document.core_properties
1 parent 783cf9f commit 652fc43

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
7878
.. |_Columns| replace:: :class:`_Columns`
7979
80+
.. |CoreProperties| replace:: :class:`.CoreProperties`
81+
8082
.. |Document| replace:: :class:`.Document`
8183
8284
.. |docx| replace:: ``python-docx``

docx/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ def add_table(self, rows, cols, style='LightShading-Accent1'):
108108
table.style = style
109109
return table
110110

111+
@property
112+
def core_properties(self):
113+
"""
114+
A |CoreProperties| object providing read/write access to the core
115+
properties of this document.
116+
"""
117+
return self._package.core_properties
118+
111119
@property
112120
def inline_shapes(self):
113121
"""

docx/opc/package.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def after_unmarshal(self):
3535
# subclass
3636
pass
3737

38+
@property
39+
def core_properties(self):
40+
"""
41+
|CoreProperties| object providing read/write access to the Dublin
42+
Core properties for this document.
43+
"""
44+
raise NotImplementedError
45+
3846
def iter_rels(self):
3947
"""
4048
Generate exactly one reference to each relationship in the package by

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from docx.api import Document
1414
from docx.enum.text import WD_BREAK
1515
from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT
16+
from docx.opc.coreprops import CoreProperties
1617
from docx.package import Package
1718
from docx.parts.document import DocumentPart, InlineShapes
1819
from docx.parts.numbering import NumberingPart
@@ -131,6 +132,11 @@ def it_can_save_the_package(self, save_fixture):
131132
document.save(file_)
132133
package_.save.assert_called_once_with(file_)
133134

135+
def it_provides_access_to_the_core_properties(self, core_props_fixture):
136+
document, core_properties_ = core_props_fixture
137+
core_properties = document.core_properties
138+
assert core_properties is core_properties_
139+
134140
def it_provides_access_to_the_numbering_part(self, num_part_get_fixture):
135141
document, document_part_, numbering_part_ = num_part_get_fixture
136142
numbering_part = document.numbering_part
@@ -214,6 +220,11 @@ def add_table_fixture(self, request, document, document_part_, table_):
214220
table_
215221
)
216222

223+
@pytest.fixture
224+
def core_props_fixture(self, document, core_properties_):
225+
document._package.core_properties = core_properties_
226+
return document, core_properties_
227+
217228
@pytest.fixture
218229
def init_fixture(self, docx_, open_):
219230
return docx_, open_
@@ -249,6 +260,10 @@ def add_paragraph_(self, request, paragraph_):
249260
request, Document, 'add_paragraph', return_value=paragraph_
250261
)
251262

263+
@pytest.fixture
264+
def core_properties_(self, request):
265+
return instance_mock(request, CoreProperties)
266+
252267
@pytest.fixture
253268
def default_docx_(self, request):
254269
return var_mock(request, 'docx.api._default_docx_path')

0 commit comments

Comments
 (0)