Skip to content

Commit fb5e7d7

Browse files
author
Steve Canny
committed
doc: add Document.part
1 parent be56d1d commit fb5e7d7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

docx/document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def __init__(self, element, part):
2424
self._part = part
2525
self.__body = None
2626

27+
@property
28+
def part(self):
29+
"""
30+
The |DocumentPart| object of this document.
31+
"""
32+
return self._part
33+
2734
@property
2835
def _body(self):
2936
"""

tests/test_document.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
import pytest
1212

1313
from docx.document import _Body, Document
14+
from docx.parts.document import DocumentPart
1415

1516
from .unitutil.cxml import element
1617
from .unitutil.mock import class_mock, instance_mock
1718

1819

1920
class DescribeDocument(object):
2021

22+
def it_provides_access_to_the_document_part(self, part_fixture):
23+
document, part_ = part_fixture
24+
assert document.part is part_
25+
2126
def it_provides_access_to_the_document_body(self, body_fixture):
2227
document, body_elm, _Body_, body_ = body_fixture
2328
body = document._body
@@ -33,6 +38,11 @@ def body_fixture(self, _Body_, body_):
3338
document = Document(document_elm, None)
3439
return document, body_elm, _Body_, body_
3540

41+
@pytest.fixture
42+
def part_fixture(self, document_part_):
43+
document = Document(None, document_part_)
44+
return document, document_part_
45+
3646
# fixture components ---------------------------------------------
3747

3848
@pytest.fixture
@@ -42,3 +52,7 @@ def _Body_(self, request, body_):
4252
@pytest.fixture
4353
def body_(self, request):
4454
return instance_mock(request, _Body)
55+
56+
@pytest.fixture
57+
def document_part_(self, request):
58+
return instance_mock(request, DocumentPart)

0 commit comments

Comments
 (0)