Skip to content

Commit 72167b7

Browse files
author
Steve Canny
committed
set: add SettingsPart.settings
1 parent 6a8d207 commit 72167b7

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

docx/parts/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010

1111
from ..opc.part import XmlPart
12+
from ..settings import Settings
1213

1314

1415
class SettingsPart(XmlPart):
@@ -29,4 +30,4 @@ def settings(self):
2930
A |Settings| proxy object for the `w:settings` element in this part,
3031
containing the document-level settings for this document.
3132
"""
32-
raise NotImplementedError
33+
return Settings(self.element)

tests/parts/test_settings.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Test suite for the docx.parts.settings module
5+
"""
6+
7+
from __future__ import (
8+
absolute_import, division, print_function, unicode_literals
9+
)
10+
11+
import pytest
12+
13+
from docx.parts.settings import SettingsPart
14+
from docx.settings import Settings
15+
16+
from ..unitutil.cxml import element
17+
from ..unitutil.mock import class_mock, instance_mock
18+
19+
20+
class DescribeSettingsPart(object):
21+
22+
def it_provides_access_to_its_settings(self, settings_fixture):
23+
settings_part, Settings_, settings_ = settings_fixture
24+
settings = settings_part.settings
25+
Settings_.assert_called_once_with(settings_part.element)
26+
assert settings is settings_
27+
28+
# fixtures -------------------------------------------------------
29+
30+
@pytest.fixture
31+
def settings_fixture(self, Settings_, settings_):
32+
settings_elm = element('w:settings')
33+
settings_part = SettingsPart(None, None, settings_elm, None)
34+
return settings_part, Settings_, settings_
35+
36+
# fixture components ---------------------------------------------
37+
38+
@pytest.fixture
39+
def Settings_(self, request, settings_):
40+
return class_mock(
41+
request, 'docx.parts.settings.Settings', return_value=settings_
42+
)
43+
44+
@pytest.fixture
45+
def settings_(self, request):
46+
return instance_mock(request, Settings)

0 commit comments

Comments
 (0)