Skip to content

Commit c293458

Browse files
author
Steve Canny
committed
body: add _Body.clear_content()
1 parent 0997949 commit c293458

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

docx/parts.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ def add_paragraph(self):
5757
p = self._body.add_p()
5858
return Paragraph(p)
5959

60+
def clear_content(self):
61+
"""
62+
Return this |_Body| instance after clearing it of all content.
63+
Section properties for the main document story, if present, are
64+
preserved.
65+
"""
66+
self._body.clear_content()
67+
return self
68+
6069
@property
6170
def paragraphs(self):
6271
if not hasattr(self._body, 'p'):

tests/test_parts.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,13 @@ def it_provides_access_to_its_paragraphs_as_a_sequence(self, Paragraph_):
109109
def it_returns_an_empty_sequence_when_it_contains_no_paragraphs(self):
110110
body = _Body(a_body().element)
111111
assert body.paragraphs == ()
112+
113+
def it_can_clear_itself_of_all_content_it_holds(self):
114+
# mockery ----------------------
115+
body_elm = Mock(name='body_elm')
116+
body = _Body(body_elm)
117+
# exercise ---------------------
118+
retval = body.clear_content()
119+
# verify -----------------------
120+
body_elm.clear_content.assert_called_once_with()
121+
assert retval is body

0 commit comments

Comments
 (0)