-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest_header.py
More file actions
71 lines (55 loc) · 2.47 KB
/
test_header.py
File metadata and controls
71 lines (55 loc) · 2.47 KB
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
64
65
66
67
68
69
70
71
# encoding: utf-8
"""
Test suite for the docx.header module
"""
from __future__ import (
absolute_import, print_function, unicode_literals, division
)
import pytest
from docx.enum.header import WD_HEADER_FOOTER
from docx.header import _BaseHeaderFooter, Header, HeaderFooterBody
from docx.parts.document import DocumentPart
from .unitutil.cxml import element
from .unitutil.mock import call, instance_mock, property_mock
class Describe_BaseHeaderFooter(object):
def it_knows_whether_it_is_linked_to_previous(self, is_linked_fixture):
header, expected_value = is_linked_fixture
assert header.is_linked_to_previous is expected_value
def it_provides_access_to_its_body(self, body_fixture):
header, calls, expected_value = body_fixture
body = header.body
assert header.part.related_hdrftr_body.call_args_list == calls
assert body == expected_value
# fixtures -------------------------------------------------------
@pytest.fixture(params=[
('w:sectPr', None),
('w:sectPr/w:headerReference{w:type=even,r:id=rId6}', None),
('w:sectPr/w:headerReference{w:type=default,r:id=rId8}', 'rId8'),
])
def body_fixture(self, request, body_, part_prop_, document_part_):
sectPr_cxml, rId = request.param
header = Header(element(sectPr_cxml), None, WD_HEADER_FOOTER.PRIMARY)
calls, expected_value = ([call(rId)], body_) if rId else ([], None)
document_part_.related_hdrftr_body.return_value = body_
return header, calls, expected_value
@pytest.fixture(params=[
('w:sectPr', True),
('w:sectPr/w:headerReference{w:type=default}', False),
('w:sectPr/w:headerReference{w:type=even}', True),
])
def is_linked_fixture(self, request):
sectPr_cxml, expected_value = request.param
header = Header(element(sectPr_cxml), None, WD_HEADER_FOOTER.PRIMARY)
return header, expected_value
# fixture components ---------------------------------------------
@pytest.fixture
def body_(self, request):
return instance_mock(request, HeaderFooterBody)
@pytest.fixture
def document_part_(self, request):
return instance_mock(request, DocumentPart)
@pytest.fixture
def part_prop_(self, request, document_part_):
return property_mock(
request, _BaseHeaderFooter, 'part', return_value=document_part_
)