File: test_header.py

package info (click to toggle)
python-docxcompose 1.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,100 kB
  • sloc: python: 2,336; makefile: 14; xml: 5; sh: 3
file content (44 lines) | stat: -rw-r--r-- 1,339 bytes parent folder | download | duplicates (3)
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
from docx import Document
from docxcompose.composer import Composer
from docxcompose.utils import xpath
from utils import ComposedDocument
from utils import docx_path
from utils import FixtureDocument
import pytest


def test_header_and_footer_refs_in_paragraph_props_get_removed(header_footer):
    refs = xpath(
        header_footer.doc.element.body,
        './/w:pPr/w:sectPr/w:headerReference|.//w:pPr/w:sectPr/w:footerReference')
    assert len(refs) == 0


def test_master_header_and_footer_are_preserved_when_adding_sections():
    doc = FixtureDocument("master_header_footer_with_sections.docx")
    composed = ComposedDocument(
        "master_header_footer.docx", "header_footer_sections.docx")

    assert composed == doc


def test_header_footer():
    doc = FixtureDocument("header_footer.docx")
    composed = ComposedDocument(
        "header_footer.docx", "header_footer.docx")
    assert composed == doc


def test_header_footer_sections():
    doc = FixtureDocument("header_footer_sections.docx")
    composed = ComposedDocument(
        "header_footer_sections.docx", "header_footer_sections.docx")

    assert composed == doc


@pytest.fixture
def header_footer():
    composer = Composer(Document(docx_path("master.docx")))
    composer.append(Document(docx_path("header_footer_sections.docx")))
    return composer