Skip to content

Commit 9be433b

Browse files
committed
bmk: add _Bookmark.is_closed
1 parent 99778bb commit 9be433b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

docx/bookmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def id(self):
9292
@property
9393
def is_closed(self):
9494
"""True if this bookmark has both a start and end element."""
95-
raise NotImplementedError
95+
return self._bookmarkEnd is not None
9696

9797
@property
9898
def name(self):

tests/test_bookmark.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ def it_knows_its_id(self):
214214

215215
assert bookmark.id == 42
216216

217+
def it_knows_whether_it_is_closed(self, is_closed_fixture):
218+
bookmarkStart, bookmarkEnd, expected_value = is_closed_fixture
219+
bookmark = _Bookmark((bookmarkStart, bookmarkEnd))
220+
221+
is_closed = bookmark.is_closed
222+
223+
assert is_closed == expected_value
224+
217225
def it_knows_its_name(self):
218226
bookmarkStart = element("w:bookmarkStart{w:name=bmk-0}")
219227
bookmarkEnd = element("w:bookmarkEnd")
@@ -222,6 +230,21 @@ def it_knows_its_name(self):
222230

223231
assert bookmark.name == "bmk-0"
224232

233+
# fixtures -------------------------------------------------------
234+
235+
@pytest.fixture(
236+
params=[
237+
(None, None, False), # ---not expected---
238+
("w:bookmarkStart", None, False),
239+
("w:bookmarkStart", "w:bookmarkEnd", True),
240+
]
241+
)
242+
def is_closed_fixture(self, request):
243+
bookmarkStart_cxml, bookmarkEnd_cxml, expected_value = request.param
244+
bookmarkStart = element(bookmarkStart_cxml) if bookmarkStart_cxml else None
245+
bookmarkEnd = element(bookmarkEnd_cxml) if bookmarkEnd_cxml else None
246+
return bookmarkStart, bookmarkEnd, expected_value
247+
225248

226249
class Describe_DocumentBookmarkFinder(object):
227250
def it_finds_all_the_bookmark_pairs_in_the_document(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy