44Test suite for the docx.oxml.parts module.
55"""
66
7- from docx .oxml .text import CT_P
7+ from __future__ import absolute_import , print_function , unicode_literals
8+
9+ import pytest
810
911from .unitdata .document import a_body
10- from ..unitdata .text import a_p , a_sectPr
12+ from ..unitdata .section import a_type
13+ from ..unitdata .text import a_p , a_pPr , a_sectPr
1114
1215
1316class DescribeCT_Body (object ):
1417
15- def it_can_add_a_p_to_itself (self ):
16- """
17- Return a newly created |CT_P| element that has been added after any
18- existing content.
19- """
20- cases = (
21- (a_body ().with_nsdecls (),
22- a_body ().with_nsdecls ().with_child (a_p ())),
23- (a_body ().with_nsdecls ().with_child (a_sectPr ()),
24- a_body ().with_nsdecls ().with_child (a_p ()).with_child (a_sectPr ())),
25- )
26- for before_body_bldr , after_body_bldr in cases :
27- body = before_body_bldr .element
28- # exercise -----------------
29- p = body .add_p ()
30- # verify -------------------
31- assert body .xml == after_body_bldr .xml ()
32- assert isinstance (p , CT_P )
33-
3418 def it_can_clear_all_the_content_it_holds (self ):
3519 """
3620 Remove all content child elements from this <w:body> element.
@@ -51,3 +35,29 @@ def it_can_clear_all_the_content_it_holds(self):
5135 body .clear_content ()
5236 # verify -------------------
5337 assert body .xml == after_body_bldr .xml ()
38+
39+ def it_can_add_a_section_break (self , section_break_fixture ):
40+ body , expected_xml = section_break_fixture
41+ sectPr = body .add_section_break ()
42+ assert body .xml == expected_xml
43+ assert sectPr is body .get_or_add_sectPr ()
44+
45+ # fixtures -------------------------------------------------------
46+
47+ @pytest .fixture
48+ def section_break_fixture (self ):
49+ body = (
50+ a_body ().with_nsdecls ().with_child (
51+ a_sectPr ().with_child (
52+ a_type ().with_val ('foobar' )))
53+ ).element
54+ expected_xml = (
55+ a_body ().with_nsdecls ().with_child (
56+ a_p ().with_child (
57+ a_pPr ().with_child (
58+ a_sectPr ().with_child (
59+ a_type ().with_val ('foobar' ))))).with_child (
60+ a_sectPr ().with_child (
61+ a_type ().with_val ('foobar' )))
62+ ).xml ()
63+ return body , expected_xml
0 commit comments