Skip to content

Commit 185fbb5

Browse files
author
Steve Canny
committed
test: rewrite test for _Body.clear_content()
1 parent ee287b4 commit 185fbb5

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

tests/test_parts.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,13 @@ def it_can_add_a_paragraph_to_itself(self, add_paragraph_fixture):
8585
assert body._body.xml == expected_xml
8686
assert isinstance(p, Paragraph)
8787

88-
def it_can_clear_itself_of_all_content_it_holds(self):
89-
# mockery ----------------------
90-
body_elm = Mock(name='body_elm')
91-
body = _Body(body_elm)
92-
# exercise ---------------------
93-
retval = body.clear_content()
94-
# verify -----------------------
95-
body_elm.clear_content.assert_called_once_with()
96-
assert retval is body
88+
def it_can_clear_itself_of_all_content_it_holds(
89+
self, clear_content_fixture):
90+
body, expected_xml = clear_content_fixture
91+
_body = body.clear_content()
92+
assert body._body.xml == expected_xml
93+
print(body._body.xml)
94+
assert _body is body
9795

9896
def it_provides_access_to_the_paragraphs_it_contains(
9997
self, body_with_paragraphs):
@@ -137,3 +135,20 @@ def body_with_paragraphs(self):
137135
.element
138136
)
139137
return _Body(body_elm)
138+
139+
@pytest.fixture(params=[False, True])
140+
def clear_content_fixture(self, request):
141+
has_sectPr = request.param
142+
# body element -----------------
143+
body_bldr = a_body().with_nsdecls()
144+
body_bldr.with_child(a_p())
145+
if has_sectPr:
146+
body_bldr.with_child(a_sectPr())
147+
body_elm = body_bldr.element
148+
body = _Body(body_elm)
149+
# expected XML -----------------
150+
body_bldr = a_body().with_nsdecls()
151+
if has_sectPr:
152+
body_bldr.with_child(a_sectPr())
153+
expected_xml = body_bldr.xml()
154+
return body, expected_xml

0 commit comments

Comments
 (0)