Skip to content

Commit f60fddd

Browse files
author
Steve Canny
committed
set: configure loader for SettingsPart
1 parent 72167b7 commit f60fddd

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

docx/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from docx.parts.document import DocumentPart
1515
from docx.parts.image import ImagePart
1616
from docx.parts.numbering import NumberingPart
17+
from docx.parts.settings import SettingsPart
1718
from docx.parts.styles import StylesPart
1819

1920

@@ -27,6 +28,7 @@ def part_class_selector(content_type, reltype):
2728
PartFactory.part_type_for[CT.OPC_CORE_PROPERTIES] = CorePropertiesPart
2829
PartFactory.part_type_for[CT.WML_DOCUMENT_MAIN] = DocumentPart
2930
PartFactory.part_type_for[CT.WML_NUMBERING] = NumberingPart
31+
PartFactory.part_type_for[CT.WML_SETTINGS] = SettingsPart
3032
PartFactory.part_type_for[CT.WML_STYLES] = StylesPart
3133

3234
del (

tests/parts/test_settings.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@
1010

1111
import pytest
1212

13+
from docx.opc.constants import CONTENT_TYPE as CT
14+
from docx.opc.part import PartFactory
15+
from docx.package import Package
1316
from docx.parts.settings import SettingsPart
1417
from docx.settings import Settings
1518

1619
from ..unitutil.cxml import element
17-
from ..unitutil.mock import class_mock, instance_mock
20+
from ..unitutil.mock import class_mock, instance_mock, method_mock
1821

1922

2023
class DescribeSettingsPart(object):
2124

25+
def it_is_used_by_loader_to_construct_settings_part(self, load_fixture):
26+
partname, content_type, blob, package_, settings_part_ = load_fixture
27+
part = PartFactory(partname, content_type, None, blob, package_)
28+
SettingsPart.load.assert_called_once_with(
29+
partname, content_type, blob, package_
30+
)
31+
assert part is settings_part_
32+
2233
def it_provides_access_to_its_settings(self, settings_fixture):
2334
settings_part, Settings_, settings_ = settings_fixture
2435
settings = settings_part.settings
@@ -27,6 +38,13 @@ def it_provides_access_to_its_settings(self, settings_fixture):
2738

2839
# fixtures -------------------------------------------------------
2940

41+
@pytest.fixture
42+
def load_fixture(self, load_, package_, settings_part_):
43+
partname, blob = 'partname', 'blob'
44+
content_type = CT.WML_SETTINGS
45+
load_.return_value = settings_part_
46+
return partname, content_type, blob, package_, settings_part_
47+
3048
@pytest.fixture
3149
def settings_fixture(self, Settings_, settings_):
3250
settings_elm = element('w:settings')
@@ -35,6 +53,14 @@ def settings_fixture(self, Settings_, settings_):
3553

3654
# fixture components ---------------------------------------------
3755

56+
@pytest.fixture
57+
def load_(self, request):
58+
return method_mock(request, SettingsPart, 'load')
59+
60+
@pytest.fixture
61+
def package_(self, request):
62+
return instance_mock(request, Package)
63+
3864
@pytest.fixture
3965
def Settings_(self, request, settings_):
4066
return class_mock(
@@ -44,3 +70,7 @@ def Settings_(self, request, settings_):
4470
@pytest.fixture
4571
def settings_(self, request):
4672
return instance_mock(request, Settings)
73+
74+
@pytest.fixture
75+
def settings_part_(self, request):
76+
return instance_mock(request, SettingsPart)

0 commit comments

Comments
 (0)