Skip to content

Commit ea2f8b4

Browse files
author
Steve Canny
committed
style: add Document.styles
1 parent 2c73213 commit ea2f8b4

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

docx/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def sections(self):
159159
"""
160160
return self._document_part.sections
161161

162+
@property
163+
def styles(self):
164+
"""
165+
A |Styles| object providing access to the styles for this document.
166+
"""
167+
return self._document_part.styles
168+
162169
@lazyproperty
163170
def styles_part(self):
164171
"""

docx/parts/document.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ def sections(self):
102102
"""
103103
return Sections(self._element)
104104

105+
@property
106+
def styles(self):
107+
"""
108+
A |Styles| object providing access to the styles in the styles part
109+
of this document.
110+
"""
111+
raise NotImplementedError
112+
105113
@property
106114
def tables(self):
107115
"""

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from docx.parts.styles import StylesPart
2121
from docx.section import Section
2222
from docx.shape import InlineShape
23+
from docx.styles.styles import Styles
2324
from docx.table import Table
2425
from docx.text.paragraph import Paragraph
2526
from docx.text.run import Run
@@ -138,6 +139,11 @@ def it_provides_access_to_the_core_properties(self, core_props_fixture):
138139
core_properties = document.core_properties
139140
assert core_properties is core_properties_
140141

142+
def it_provides_access_to_its_styles(self, styles_fixture):
143+
document, styles_ = styles_fixture
144+
styles = document.styles
145+
assert styles is styles_
146+
141147
def it_provides_access_to_the_numbering_part(self, num_part_get_fixture):
142148
document, document_part_, numbering_part_ = num_part_get_fixture
143149
numbering_part = document.numbering_part
@@ -249,6 +255,11 @@ def save_fixture(self, request, open_, package_):
249255
document = Document()
250256
return document, package_, file_
251257

258+
@pytest.fixture
259+
def styles_fixture(self, document, styles_):
260+
document._document_part.styles = styles_
261+
return document, styles_
262+
252263
@pytest.fixture
253264
def tables_fixture(self, document, tables_):
254265
return document, tables_
@@ -362,6 +373,10 @@ def section_(self, request):
362373
def start_type_(self, request):
363374
return instance_mock(request, int)
364375

376+
@pytest.fixture
377+
def styles_(self, request):
378+
return instance_mock(request, Styles)
379+
365380
@pytest.fixture
366381
def StylesPart_(self, request, styles_part_):
367382
StylesPart_ = class_mock(request, 'docx.api.StylesPart')

0 commit comments

Comments
 (0)