-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest_document.py
More file actions
43 lines (35 loc) · 1.35 KB
/
test_document.py
File metadata and controls
43 lines (35 loc) · 1.35 KB
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