Skip to content

Commit e08d95c

Browse files
author
Steve Canny
committed
doc: add Document.core_properties
1 parent bd16fc7 commit e08d95c

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docx/document.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ def add_table(self, rows, cols, style='Light Shading Accent 1'):
9898
table.style = style
9999
return table
100100

101+
@property
102+
def core_properties(self):
103+
"""
104+
A |CoreProperties| object providing read/write access to the core
105+
properties of this document.
106+
"""
107+
return self._part.core_properties
108+
101109
@property
102110
def part(self):
103111
"""

docx/parts/document.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ def body(self):
3131
"""
3232
return _Body(self._element.body, self)
3333

34+
@property
35+
def core_properties(self):
36+
"""
37+
A |CoreProperties| object providing read/write access to the core
38+
properties of this document.
39+
"""
40+
raise NotImplementedError
41+
3442
@property
3543
def document(self):
3644
"""

tests/test_document.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from docx.document import _Body, Document
1414
from docx.enum.section import WD_SECTION
1515
from docx.enum.text import WD_BREAK
16+
from docx.opc.coreprops import CoreProperties
1617
from docx.parts.document import DocumentPart
1718
from docx.shape import InlineShape
1819
from docx.table import Table
@@ -78,6 +79,11 @@ def it_can_add_a_table(self, add_table_fixture):
7879
assert table == table_
7980
assert table.style == style
8081

82+
def it_provides_access_to_its_core_properties(self, core_props_fixture):
83+
document, core_properties_ = core_props_fixture
84+
core_properties = document.core_properties
85+
assert core_properties is core_properties_
86+
8187
def it_provides_access_to_the_document_part(self, part_fixture):
8288
document, part_ = part_fixture
8389
assert document.part is part_
@@ -162,6 +168,12 @@ def body_fixture(self, _Body_, body_):
162168
document = Document(document_elm, None)
163169
return document, body_elm, _Body_, body_
164170

171+
@pytest.fixture
172+
def core_props_fixture(self, document_part_, core_properties_):
173+
document = Document(None, document_part_)
174+
document_part_.core_properties = core_properties_
175+
return document, core_properties_
176+
165177
@pytest.fixture
166178
def part_fixture(self, document_part_):
167179
document = Document(None, document_part_)
@@ -185,6 +197,10 @@ def body_(self, request):
185197
def body_prop_(self, request, body_):
186198
return property_mock(request, Document, '_body', return_value=body_)
187199

200+
@pytest.fixture
201+
def core_properties_(self, request):
202+
return instance_mock(request, CoreProperties)
203+
188204
@pytest.fixture
189205
def document_part_(self, request):
190206
return instance_mock(request, DocumentPart)

0 commit comments

Comments
 (0)