Skip to content

Commit 5541292

Browse files
author
Steve Canny
committed
api: add _Document.save()
1 parent ce4b630 commit 5541292

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

docx/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ class _Document(object):
4747
def __init__(self, pkg, document_part):
4848
super(_Document, self).__init__()
4949
self._document = document_part
50+
self._pkg = pkg
5051

5152
@property
5253
def body(self):
5354
"""
5455
Return a reference to the |Body| instance for this document.
5556
"""
5657
return self._document.body
58+
59+
def save(self, file_):
60+
"""
61+
Save this document to *file_*, where *file_* can be either a path to
62+
a file (a string) or a file-like object.
63+
"""
64+
return self._pkg.save(file_)

tests/test_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ def it_provides_access_to_the_document_body(self):
8181
body = doc.body
8282
# verify -----------------------
8383
assert body is document_part.body
84+
85+
def it_can_save_the_package(self):
86+
pkg, file_ = (Mock(name='pkg'), Mock(name='file_'))
87+
_Document(pkg, None).save(file_)
88+
pkg.save.assert_called_once_with(file_)

0 commit comments

Comments
 (0)