Skip to content

Commit 2afdf82

Browse files
author
Steve Canny
committed
doc: add Document.styles
1 parent 13b1e74 commit 2afdf82

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

docx/document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ def sections(self):
147147
"""
148148
return Sections(self._element)
149149

150+
@property
151+
def styles(self):
152+
"""
153+
A |Styles| object providing access to the styles in this document.
154+
"""
155+
return self._part.styles
156+
150157
@property
151158
def _body(self):
152159
"""

tests/test_document.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from docx.parts.document import DocumentPart, InlineShapes
1818
from docx.section import Sections
1919
from docx.shape import InlineShape
20+
from docx.styles.styles import Styles
2021
from docx.table import Table
2122
from docx.text.paragraph import Paragraph
2223
from docx.text.run import Run
@@ -92,8 +93,7 @@ def it_provides_access_to_its_core_properties(self, core_props_fixture):
9293

9394
def it_provides_access_to_its_inline_shapes(self, inline_shapes_fixture):
9495
document, inline_shapes_ = inline_shapes_fixture
95-
inline_shapes = document.inline_shapes
96-
assert inline_shapes is inline_shapes_
96+
assert document.inline_shapes is inline_shapes_
9797

9898
def it_provides_access_to_its_paragraphs(self, paragraphs_fixture):
9999
document, paragraphs_ = paragraphs_fixture
@@ -106,6 +106,10 @@ def it_provides_access_to_its_sections(self, sections_fixture):
106106
Sections_.assert_called_once_with(document._element)
107107
assert sections is sections_
108108

109+
def it_provides_access_to_its_styles(self, styles_fixture):
110+
document, styles_ = styles_fixture
111+
assert document.styles is styles_
112+
109113
def it_provides_access_to_the_document_part(self, part_fixture):
110114
document, part_ = part_fixture
111115
assert document.part is part_
@@ -226,6 +230,12 @@ def sections_fixture(self, Sections_, sections_):
226230
Sections_.return_value = sections_
227231
return document, Sections_, sections_
228232

233+
@pytest.fixture
234+
def styles_fixture(self, document_part_, styles_):
235+
document = Document(None, document_part_)
236+
document_part_.styles = styles_
237+
return document, styles_
238+
229239
# fixture components ---------------------------------------------
230240

231241
@pytest.fixture
@@ -284,6 +294,10 @@ def Sections_(self, request):
284294
def sections_(self, request):
285295
return instance_mock(request, Sections)
286296

297+
@pytest.fixture
298+
def styles_(self, request):
299+
return instance_mock(request, Styles)
300+
287301
@pytest.fixture
288302
def table_(self, request):
289303
return instance_mock(request, Table, style='UNASSIGNED')

0 commit comments

Comments
 (0)