Skip to content

Commit 0c90ce3

Browse files
committed
hdr: add PartFactory loads FooterPart
1 parent 47d7e4b commit 0c90ce3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

docx/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from docx.opc.parts.coreprops import CorePropertiesPart
1313

1414
from docx.parts.document import DocumentPart
15-
from docx.parts.hdrftr import HeaderPart
15+
from docx.parts.hdrftr import FooterPart, HeaderPart
1616
from docx.parts.image import ImagePart
1717
from docx.parts.numbering import NumberingPart
1818
from docx.parts.settings import SettingsPart
@@ -28,6 +28,7 @@ def part_class_selector(content_type, reltype):
2828
PartFactory.part_class_selector = part_class_selector
2929
PartFactory.part_type_for[CT.OPC_CORE_PROPERTIES] = CorePropertiesPart
3030
PartFactory.part_type_for[CT.WML_DOCUMENT_MAIN] = DocumentPart
31+
PartFactory.part_type_for[CT.WML_FOOTER] = FooterPart
3132
PartFactory.part_type_for[CT.WML_HEADER] = HeaderPart
3233
PartFactory.part_type_for[CT.WML_NUMBERING] = NumberingPart
3334
PartFactory.part_type_for[CT.WML_SETTINGS] = SettingsPart
@@ -37,6 +38,7 @@ def part_class_selector(content_type, reltype):
3738
CT,
3839
CorePropertiesPart,
3940
DocumentPart,
41+
FooterPart,
4042
HeaderPart,
4143
NumberingPart,
4244
PartFactory,

docx/oxml/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
9393
CT_SectType,
9494
)
9595
register_element_cls("w:footerReference", CT_HdrFtrRef)
96+
register_element_cls("w:ftr", CT_HdrFtr)
9697
register_element_cls("w:hdr", CT_HdrFtr)
9798
register_element_cls("w:headerReference", CT_HdrFtrRef)
9899
register_element_cls("w:pgMar", CT_PageMar)

features/hdr-header-footer.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ Feature: Header and footer behaviors
5757
| with no | True |
5858

5959

60-
@wip
6160
Scenario: _Footer inherits content
6261
Given a _Footer object with a footer definition as footer
6362
And the next _Footer object with no footer definition as footer_2

tests/parts/test_hdrftr.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717

1818
class DescribeFooterPart(object):
1919

20+
def it_is_used_by_loader_to_construct_footer_part(
21+
self, package_, FooterPart_load_, footer_part_
22+
):
23+
partname = "footer1.xml"
24+
content_type = CT.WML_FOOTER
25+
reltype = RT.FOOTER
26+
blob = "<w:ftr/>"
27+
FooterPart_load_.return_value = footer_part_
28+
29+
part = PartFactory(partname, content_type, reltype, blob, package_)
30+
31+
FooterPart_load_.assert_called_once_with(partname, content_type, blob, package_)
32+
assert part is footer_part_
33+
2034
def it_can_create_a_new_footer_part(
2135
self, package_, _default_footer_xml_, parse_xml_, _init_
2236
):
@@ -49,6 +63,14 @@ def it_loads_default_footer_XML_from_a_template_to_help(self):
4963
def _default_footer_xml_(self, request):
5064
return method_mock(request, FooterPart, "_default_footer_xml", autospec=False)
5165

66+
@pytest.fixture
67+
def footer_part_(self, request):
68+
return instance_mock(request, FooterPart)
69+
70+
@pytest.fixture
71+
def FooterPart_load_(self, request):
72+
return method_mock(request, FooterPart, "load", autospec=False)
73+
5274
@pytest.fixture
5375
def _init_(self, request):
5476
return initializer_mock(request, FooterPart)

0 commit comments

Comments
 (0)