forked from python-openxml/python-docx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_settings.py
63 lines (50 loc) · 2.12 KB
/
test_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Unit test suite for the docx.settings module."""
import pytest
from docx.settings import Settings
from .unitutil.cxml import element, xml
class DescribeSettings:
def it_knows_when_the_document_has_distinct_odd_and_even_headers(
self, odd_and_even_get_fixture
):
settings_elm, expected_value = odd_and_even_get_fixture
settings = Settings(settings_elm)
odd_and_even_pages_header_footer = settings.odd_and_even_pages_header_footer
assert odd_and_even_pages_header_footer is expected_value
def it_can_change_whether_the_document_has_distinct_odd_and_even_headers(
self, odd_and_even_set_fixture
):
settings_elm, value, expected_xml = odd_and_even_set_fixture
settings = Settings(settings_elm)
settings.odd_and_even_pages_header_footer = value
assert settings_elm.xml == expected_xml
# fixtures -------------------------------------------------------
@pytest.fixture(
params=[
("w:settings", False),
("w:settings/w:evenAndOddHeaders", True),
("w:settings/w:evenAndOddHeaders{w:val=0}", False),
("w:settings/w:evenAndOddHeaders{w:val=1}", True),
("w:settings/w:evenAndOddHeaders{w:val=true}", True),
]
)
def odd_and_even_get_fixture(self, request):
settings_cxml, expected_value = request.param
settings_elm = element(settings_cxml)
return settings_elm, expected_value
@pytest.fixture(
params=[
("w:settings", True, "w:settings/w:evenAndOddHeaders"),
("w:settings/w:evenAndOddHeaders", False, "w:settings"),
(
"w:settings/w:evenAndOddHeaders{w:val=1}",
True,
"w:settings/w:evenAndOddHeaders",
),
("w:settings/w:evenAndOddHeaders{w:val=off}", False, "w:settings"),
]
)
def odd_and_even_set_fixture(self, request):
settings_cxml, value, expected_cxml = request.param
settings_elm = element(settings_cxml)
expected_xml = xml(expected_cxml)
return settings_elm, value, expected_xml