88
99import pytest
1010
11- from .unitdata .document import a_body
12- from ..unitdata .section import a_type
13- from ..unitdata .text import a_p , a_pPr , a_sectPr
11+ from ...unitutil .cxml import element , xml
1412
1513
1614class DescribeCT_Body (object ):
1715
18- def it_can_clear_all_the_content_it_holds (self ):
19- """
20- Remove all content child elements from this <w:body> element.
21- """
22- cases = (
23- (a_body ().with_nsdecls (),
24- a_body ().with_nsdecls ()),
25- (a_body ().with_nsdecls ().with_child (a_p ()),
26- a_body ().with_nsdecls ()),
27- (a_body ().with_nsdecls ().with_child (a_sectPr ()),
28- a_body ().with_nsdecls ().with_child (a_sectPr ())),
29- (a_body ().with_nsdecls ().with_child (a_p ()).with_child (a_sectPr ()),
30- a_body ().with_nsdecls ().with_child (a_sectPr ())),
31- )
32- for before_body_bldr , after_body_bldr in cases :
33- body = before_body_bldr .element
34- # exercise -----------------
35- body .clear_content ()
36- # verify -------------------
37- assert body .xml == after_body_bldr .xml ()
16+ def it_can_clear_all_its_content (self , clear_fixture ):
17+ body , expected_xml = clear_fixture
18+ body .clear_content ()
19+ assert body .xml == expected_xml
3820
3921 def it_can_add_a_section_break (self , section_break_fixture ):
4022 body , expected_xml = section_break_fixture
@@ -44,20 +26,26 @@ def it_can_add_a_section_break(self, section_break_fixture):
4426
4527 # fixtures -------------------------------------------------------
4628
29+ @pytest .fixture (params = [
30+ ('w:body' , 'w:body' ),
31+ ('w:body/w:p' , 'w:body' ),
32+ ('w:body/w:tbl' , 'w:body' ),
33+ ('w:body/w:sectPr' , 'w:body/w:sectPr' ),
34+ ('w:body/(w:p, w:sectPr)' , 'w:body/w:sectPr' ),
35+ ])
36+ def clear_fixture (self , request ):
37+ before_cxml , after_cxml = request .param
38+ body = element (before_cxml )
39+ expected_xml = xml (after_cxml )
40+ return body , expected_xml
41+
4742 @pytest .fixture
4843 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 ()
44+ body = element ('w:body/w:sectPr/w:type{w:val=foobar}' )
45+ expected_xml = xml (
46+ 'w:body/('
47+ ' w:p/w:pPr/w:sectPr/w:type{w:val=foobar},'
48+ ' w:sectPr/w:type{w:val=foobar}'
49+ ')'
50+ )
6351 return body , expected_xml
0 commit comments