|
11 | 11 | from docx.enum.section import WD_ORIENT, WD_SECTION
|
12 | 12 | from docx.section import Section, Sections
|
13 | 13 | from docx.shared import Inches
|
| 14 | +from docx.header import Header |
14 | 15 |
|
15 | 16 | from .unitutil.cxml import element, xml
|
| 17 | +from .unitutil.mock import instance_mock, class_mock |
16 | 18 |
|
17 | 19 |
|
18 | 20 | class DescribeSections(object):
|
@@ -61,6 +63,12 @@ def document_elm(self):
|
61 | 63 |
|
62 | 64 | class DescribeSection(object):
|
63 | 65 |
|
| 66 | + def it_provides_access_to_its_header(self, header_fixture): |
| 67 | + section, Header_, sectPr, header_ = header_fixture |
| 68 | + header = section.header |
| 69 | + Header_.assert_called_once_with(sectPr) |
| 70 | + assert header is header_ |
| 71 | + |
64 | 72 | def it_knows_its_start_type(self, start_type_get_fixture):
|
65 | 73 | section, expected_start_type = start_type_get_fixture
|
66 | 74 | assert section.start_type is expected_start_type
|
@@ -111,6 +119,12 @@ def it_can_change_its_page_margins(self, margins_set_fixture):
|
111 | 119 |
|
112 | 120 | # fixtures -------------------------------------------------------
|
113 | 121 |
|
| 122 | + @pytest.fixture |
| 123 | + def header_fixture(self, Header_, header_): |
| 124 | + sectPr = element('w:sectPr') |
| 125 | + section = Section(sectPr) |
| 126 | + return section, Header_, sectPr, header_ |
| 127 | + |
114 | 128 | @pytest.fixture(params=[
|
115 | 129 | ('w:sectPr/w:pgMar{w:left=120}', 'left_margin', 76200),
|
116 | 130 | ('w:sectPr/w:pgMar{w:right=240}', 'right_margin', 152400),
|
@@ -247,3 +261,16 @@ def start_type_set_fixture(self, request):
|
247 | 261 | section = Section(element(initial_cxml))
|
248 | 262 | expected_xml = xml(expected_cxml)
|
249 | 263 | return section, new_start_type, expected_xml
|
| 264 | + |
| 265 | + # fixture components --------------------------------------------- |
| 266 | + |
| 267 | + @pytest.fixture |
| 268 | + def header_(self, request): |
| 269 | + return instance_mock(request, Header) |
| 270 | + |
| 271 | + @pytest.fixture |
| 272 | + def Header_(self, request, header_): |
| 273 | + return class_mock( |
| 274 | + request, 'docx.section.Header', |
| 275 | + return_value=header_ |
| 276 | + ) |
0 commit comments