@@ -50,6 +50,29 @@ def it_can_add_a_table(self, add_table_fixture):
5050 assert table ._element .xml == expected_xml
5151 assert table ._parent is blkcntnr
5252
53+ def it_can_end_a_bookmark (self , end_bookmark_fixture , bookmark_ ):
54+ blockContainer , bookmark_id , expected_xml = end_bookmark_fixture
55+ bookmark_ .close .return_value = bookmark_
56+ bookmark_ .id = bookmark_id
57+ bookmark_ .is_closed = False
58+ blkcntnr = BlockItemContainer (blockContainer , None )
59+
60+ bookmark = blkcntnr .end_bookmark (bookmark_ )
61+
62+ bookmark_ .close .assert_called_once_with (
63+ blockContainer .xpath ("w:bookmarkEnd" )[- 1 ]
64+ )
65+ assert blkcntnr ._element .xml == expected_xml
66+ assert bookmark is bookmark_
67+
68+ def but_it_raises_when_bookmark_is_already_closed (self , bookmark_ ):
69+ bookmark_ .is_closed = True
70+ blkcntnr = BlockItemContainer (None , None )
71+
72+ with pytest .raises (ValueError ) as e :
73+ blkcntnr .end_bookmark (bookmark_ )
74+ assert "bookmark already closed" in str (e .value )
75+
5376 def it_provides_access_to_the_paragraphs_it_contains (self , paragraphs_fixture ):
5477 # ---test len(), iterable, and indexed access---
5578 blkcntnr , expected_count = paragraphs_fixture
@@ -160,6 +183,24 @@ def bookmarks_fixture(self, request):
160183 parent_part_ = instance_mock (request , PartCls )
161184 return parent_part_
162185
186+ @pytest .fixture (
187+ params = [
188+ # ---document body---
189+ ("w:body" , 0 , "w:body/w:bookmarkEnd{w:id=0}" ),
190+ # ---table cell---
191+ ("w:tc/w:p" , 1 , "w:tc/(w:p,w:bookmarkEnd{w:id=1})" ),
192+ # ---header---
193+ ("w:hdr/w:p" , 42 , "w:hdr/(w:p,w:bookmarkEnd{w:id=42})" ),
194+ # ---footer---
195+ ("w:ftr/w:p" , 24 , "w:ftr/(w:p,w:bookmarkEnd{w:id=24})" ),
196+ ]
197+ )
198+ def end_bookmark_fixture (self , request ):
199+ cxml , bookmark_id , expected_cxml = request .param
200+ blockContainer = element (cxml )
201+ expected_xml = xml (expected_cxml )
202+ return blockContainer , bookmark_id , expected_xml
203+
163204 @pytest .fixture (
164205 params = [
165206 ("w:body" , 0 ),
0 commit comments