Skip to content

Commit 7bc7728

Browse files
committed
doc: add Document.end_bookmark()
1 parent dc793d3 commit 7bc7728

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

docx/blkcntnr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def add_table(self, rows, cols, width):
5252
self._element._insert_tbl(tbl)
5353
return Table(tbl, self)
5454

55+
def end_bookmark(self, bookmark):
56+
"""Return `bookmark` after closing it after last block item in container."""
57+
raise NotImplementedError
58+
5559
@property
5660
def paragraphs(self):
5761
"""

docx/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def core_properties(self):
114114

115115
def end_bookmark(self, bookmark):
116116
"""Return `bookmark` after closing it at end of this document."""
117-
raise NotImplementedError
117+
return self._body.end_bookmark(bookmark)
118118

119119
@property
120120
def inline_shapes(self):

tests/test_document.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ def it_can_add_a_table(self, add_table_fixture):
9090
assert table == table_
9191
assert table.style == style
9292

93-
def it_can_save_the_document_to_a_file(self, save_fixture):
94-
document, file_ = save_fixture
95-
document.save(file_)
96-
document._part.save.assert_called_once_with(file_)
97-
9893
def it_provides_access_to_its_bookmarks(self, document_part_, bookmarks_):
9994
document_part_.bookmarks = bookmarks_
10095
document = Document(None, document_part_)
@@ -108,6 +103,16 @@ def it_provides_access_to_its_core_properties(self, core_props_fixture):
108103
core_properties = document.core_properties
109104
assert core_properties is core_properties_
110105

106+
def it_can_end_a_bookmark(self, _body_prop_, body_, bookmark_):
107+
_body_prop_.return_value = body_
108+
body_.end_bookmark.return_value = bookmark_
109+
document = Document(None, None)
110+
111+
bookmark = document.end_bookmark(bookmark_)
112+
113+
body_.end_bookmark.assert_called_once_with(bookmark_)
114+
assert bookmark is bookmark_
115+
111116
def it_provides_access_to_its_inline_shapes(self, inline_shapes_fixture):
112117
document, inline_shapes_ = inline_shapes_fixture
113118
assert document.inline_shapes is inline_shapes_
@@ -117,6 +122,11 @@ def it_provides_access_to_its_paragraphs(self, paragraphs_fixture):
117122
paragraphs = document.paragraphs
118123
assert paragraphs is paragraphs_
119124

125+
def it_can_save_the_document_to_a_file(self, save_fixture):
126+
document, file_ = save_fixture
127+
document.save(file_)
128+
document._part.save.assert_called_once_with(file_)
129+
120130
def it_provides_access_to_its_sections(self, document_part_, Sections_, sections_):
121131
document_elm = element("w:document")
122132
Sections_.return_value = sections_

0 commit comments

Comments
 (0)