Skip to content

Commit 587a8a3

Browse files
author
Steve Canny
committed
style: remove dead Document.styles_part and tests
1 parent f1ad648 commit 587a8a3

File tree

5 files changed

+2
-88
lines changed

5 files changed

+2
-88
lines changed

docx/api.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT
1616
from docx.package import Package
1717
from docx.parts.numbering import NumberingPart
18-
from docx.parts.styles import StylesPart
1918
from docx.shared import lazyproperty
2019

2120

@@ -166,19 +165,6 @@ def styles(self):
166165
"""
167166
return self._document_part.styles
168167

169-
@lazyproperty
170-
def styles_part(self):
171-
"""
172-
Instance of |StylesPart| for this document. Creates an empty styles
173-
part if one is not present.
174-
"""
175-
try:
176-
return self._document_part.part_related_by(RT.STYLES)
177-
except KeyError:
178-
styles_part = StylesPart.new()
179-
self._document_part.relate_to(styles_part, RT.STYLES)
180-
return styles_part
181-
182168
@property
183169
def tables(self):
184170
"""

docx/parts/styles.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ def default(cls, package):
2525
"""
2626
raise NotImplementedError
2727

28-
@classmethod
29-
def new(cls):
30-
"""
31-
Return newly created empty styles part, containing only the root
32-
``<w:styles>`` element.
33-
"""
34-
raise NotImplementedError
35-
3628
@property
3729
def styles(self):
3830
"""

features/steps/styles.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Step implementations for styles-related features
55
"""
66

7-
from behave import given, then, when
7+
from behave import given, then
88

99
from docx import Document
1010
from docx.styles.styles import Styles
@@ -27,14 +27,6 @@ def given_a_document_having_no_styles_part(context):
2727
context.document = Document(docx_path)
2828

2929

30-
# when ====================================================
31-
32-
@when('I get the styles part from the document')
33-
def when_get_styles_part_from_document(context):
34-
document = context.document
35-
context.styles_part = document.styles_part
36-
37-
3830
# then =====================================================
3931

4032
@then('I can access a style by its UI name')
@@ -68,9 +60,3 @@ def then_I_can_iterate_over_its_styles(context):
6860
@then('len(styles) is {style_count_str}')
6961
def then_len_styles_is_style_count(context, style_count_str):
7062
assert len(context.document.styles) == int(style_count_str)
71-
72-
73-
@then('the styles part has the expected number of style definitions')
74-
def then_styles_part_has_expected_number_of_style_definitions(context):
75-
styles_part = context.styles_part
76-
assert len(styles_part.styles) == 6

features/sty-get-styles-part.feature

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/test_api.py

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from docx.package import Package
1818
from docx.parts.document import DocumentPart, InlineShapes
1919
from docx.parts.numbering import NumberingPart
20-
from docx.parts.styles import StylesPart
2120
from docx.section import Section
2221
from docx.shape import InlineShape
2322
from docx.styles.styles import Styles
@@ -134,7 +133,7 @@ def it_can_save_the_package(self, save_fixture):
134133
document.save(file_)
135134
package_.save.assert_called_once_with(file_)
136135

137-
def it_provides_access_to_the_core_properties(self, core_props_fixture):
136+
def it_provides_access_to_its_core_properties(self, core_props_fixture):
138137
document, core_properties_ = core_props_fixture
139138
core_properties = document.core_properties
140139
assert core_properties is core_properties_
@@ -162,24 +161,6 @@ def it_creates_numbering_part_on_first_access_if_not_present(
162161
)
163162
assert numbering_part is numbering_part_
164163

165-
def it_provides_access_to_the_styles_part(self, styles_part_get_fixture):
166-
document, document_part_, styles_part_ = styles_part_get_fixture
167-
styles_part = document.styles_part
168-
document_part_.part_related_by.assert_called_once_with(RT.STYLES)
169-
assert styles_part is styles_part_
170-
171-
def it_creates_styles_part_on_first_access_if_not_present(
172-
self, styles_part_create_fixture):
173-
document, StylesPart_, document_part_, styles_part_ = (
174-
styles_part_create_fixture
175-
)
176-
styles_part = document.styles_part
177-
StylesPart_.new.assert_called_once_with()
178-
document_part_.relate_to.assert_called_once_with(
179-
styles_part_, RT.STYLES
180-
)
181-
assert styles_part is styles_part_
182-
183164
# fixtures -------------------------------------------------------
184165

185166
@pytest.fixture(params=[
@@ -377,27 +358,6 @@ def start_type_(self, request):
377358
def styles_(self, request):
378359
return instance_mock(request, Styles)
379360

380-
@pytest.fixture
381-
def StylesPart_(self, request, styles_part_):
382-
StylesPart_ = class_mock(request, 'docx.api.StylesPart')
383-
StylesPart_.new.return_value = styles_part_
384-
return StylesPart_
385-
386-
@pytest.fixture
387-
def styles_part_(self, request):
388-
return instance_mock(request, StylesPart)
389-
390-
@pytest.fixture
391-
def styles_part_create_fixture(
392-
self, document, StylesPart_, document_part_, styles_part_):
393-
document_part_.part_related_by.side_effect = KeyError
394-
return document, StylesPart_, document_part_, styles_part_
395-
396-
@pytest.fixture
397-
def styles_part_get_fixture(self, document, document_part_, styles_part_):
398-
document_part_.part_related_by.return_value = styles_part_
399-
return document, document_part_, styles_part_
400-
401361
@pytest.fixture
402362
def table_(self, request):
403363
return instance_mock(request, Table, style=None)

0 commit comments

Comments
 (0)