File: test_document.py

package info (click to toggle)
python-docx 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,216 kB
  • sloc: xml: 25,323; python: 23,414; makefile: 175
file content (43 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download
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
"""Test suite for the docx.oxml.parts module."""

import pytest

from ...unitutil.cxml import element, xml


class DescribeCT_Body:
    def it_can_clear_all_its_content(self, clear_fixture):
        body, expected_xml = clear_fixture
        body.clear_content()
        assert body.xml == expected_xml

    def it_can_add_a_section_break(self, section_break_fixture):
        body, expected_xml = section_break_fixture
        sectPr = body.add_section_break()
        assert body.xml == expected_xml
        assert sectPr is body.get_or_add_sectPr()

    # fixtures -------------------------------------------------------

    @pytest.fixture(
        params=[
            ("w:body", "w:body"),
            ("w:body/w:p", "w:body"),
            ("w:body/w:tbl", "w:body"),
            ("w:body/w:sectPr", "w:body/w:sectPr"),
            ("w:body/(w:p, w:sectPr)", "w:body/w:sectPr"),
        ]
    )
    def clear_fixture(self, request):
        before_cxml, after_cxml = request.param
        body = element(before_cxml)
        expected_xml = xml(after_cxml)
        return body, expected_xml

    @pytest.fixture
    def section_break_fixture(self):
        body = element("w:body/w:sectPr/w:type{w:val=foobar}")
        expected_xml = xml(
            "w:body/(w:p/w:pPr/w:sectPr/w:type{w:val=foobar},w:sectPr/w:type{w:val=foobar})"
        )
        return body, expected_xml