Skip to content

Commit 3805d70

Browse files
author
Steve Canny
committed
doc: add Document.settings
1 parent 4f0c322 commit 3805d70

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

docx/document.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ def sections(self):
149149
"""
150150
return Sections(self._element)
151151

152+
@property
153+
def settings(self):
154+
"""
155+
A |Settings| object providing access to the document-level settings
156+
for this document.
157+
"""
158+
return self._part.settings
159+
152160
@property
153161
def styles(self):
154162
"""

docx/parts/document.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ def save(self, path_or_stream):
127127
"""
128128
self.package.save(path_or_stream)
129129

130+
@property
131+
def settings(self):
132+
"""
133+
A |Settings| object providing access to the settings in the settings
134+
part of this document.
135+
"""
136+
raise NotImplementedError
137+
130138
@property
131139
def styles(self):
132140
"""

tests/test_document.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from docx.opc.coreprops import CoreProperties
1717
from docx.parts.document import DocumentPart
1818
from docx.section import Section, Sections
19+
from docx.settings import Settings
1920
from docx.shape import InlineShape, InlineShapes
2021
from docx.shared import Length
2122
from docx.styles.styles import Styles
@@ -107,6 +108,10 @@ def it_provides_access_to_its_sections(self, sections_fixture):
107108
Sections_.assert_called_once_with(document._element)
108109
assert sections is sections_
109110

111+
def it_provides_access_to_its_settings(self, settings_fixture):
112+
document, settings_ = settings_fixture
113+
assert document.settings is settings_
114+
110115
def it_provides_access_to_its_styles(self, styles_fixture):
111116
document, styles_ = styles_fixture
112117
assert document.styles is styles_
@@ -253,6 +258,12 @@ def sections_fixture(self, Sections_, sections_):
253258
Sections_.return_value = sections_
254259
return document, Sections_, sections_
255260

261+
@pytest.fixture
262+
def settings_fixture(self, document_part_, settings_):
263+
document = Document(None, document_part_)
264+
document_part_.settings = settings_
265+
return document, settings_
266+
256267
@pytest.fixture
257268
def styles_fixture(self, document_part_, styles_):
258269
document = Document(None, document_part_)
@@ -335,6 +346,10 @@ def sections_(self, request):
335346
def sections_prop_(self, request):
336347
return property_mock(request, Document, 'sections')
337348

349+
@pytest.fixture
350+
def settings_(self, request):
351+
return instance_mock(request, Settings)
352+
338353
@pytest.fixture
339354
def styles_(self, request):
340355
return instance_mock(request, Styles)

0 commit comments

Comments
 (0)