|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +"""Unit test suite for the docx.parts.hdrftr module""" |
| 4 | + |
| 5 | +from __future__ import absolute_import, division, print_function, unicode_literals |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from docx.opc.constants import CONTENT_TYPE as CT |
| 10 | +from docx.package import Package |
| 11 | +from docx.parts.hdrftr import HeaderPart |
| 12 | + |
| 13 | +from ..unitutil.cxml import element |
| 14 | +from ..unitutil.mock import function_mock, initializer_mock, instance_mock, method_mock |
| 15 | + |
| 16 | + |
| 17 | +class DescribeHeaderPart(object): |
| 18 | + |
| 19 | + def it_can_create_a_new_header_part( |
| 20 | + self, package_, _default_header_xml_, parse_xml_, _init_ |
| 21 | + ): |
| 22 | + hdr = element("w:hdr") |
| 23 | + package_.next_partname.return_value = "/word/header42.xml" |
| 24 | + _default_header_xml_.return_value = "<w:hdr>" |
| 25 | + parse_xml_.return_value = hdr |
| 26 | + |
| 27 | + header_part = HeaderPart.new(package_) |
| 28 | + |
| 29 | + package_.next_partname.assert_called_once_with("/word/header%d.xml") |
| 30 | + _default_header_xml_.assert_called_once_with() |
| 31 | + parse_xml_.assert_called_once_with("<w:hdr>") |
| 32 | + _init_.assert_called_once_with( |
| 33 | + header_part, "/word/header42.xml", CT.WML_HEADER, hdr, package_ |
| 34 | + ) |
| 35 | + |
| 36 | + # fixture components --------------------------------------------- |
| 37 | + |
| 38 | + @pytest.fixture |
| 39 | + def _default_header_xml_(self, request): |
| 40 | + return method_mock(request, HeaderPart, "_default_header_xml", autospec=False) |
| 41 | + |
| 42 | + @pytest.fixture |
| 43 | + def _init_(self, request): |
| 44 | + return initializer_mock(request, HeaderPart, autospec=True) |
| 45 | + |
| 46 | + @pytest.fixture |
| 47 | + def package_(self, request): |
| 48 | + return instance_mock(request, Package) |
| 49 | + |
| 50 | + @pytest.fixture |
| 51 | + def parse_xml_(self, request): |
| 52 | + return function_mock(request, "docx.parts.hdrftr.parse_xml") |
0 commit comments