Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c58ac35

Browse files
Benjamin Toornstrascanny
authored andcommitted
bmk: Add _Bookmark.id
1 parent b514ea3 commit c58ac35

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

docx/bookmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, bookmark_pair):
5757
@property
5858
def id(self):
5959
"""Provides access to the bookmark id."""
60-
raise NotImplementedError
60+
return self._bookmarkStart.id
6161

6262
@property
6363
def name(self):

features/bmk-bookmarks.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Feature: Access a bookmark
1010
And bookmarks[1] is a _Bookmark object
1111
And iterating bookmarks produces 5 _Bookmark objects
1212

13-
@wip
1413
Scenario Outline: Bookmarks.get(bookmark_name)
1514
Given a Bookmarks object of length 5 as bookmarks
1615
Then bookmarks.get(<name>) returns bookmark named "<name>" with id <id>

tests/test_bookmark.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ def _iter_(self, request):
161161
class Describe_Bookmark(object):
162162
"""Unit-test suite for `docx.bookmark._Bookmark` object."""
163163

164+
def it_knows_its_id(self):
165+
bookmarkStart = element("w:bookmarkStart{w:id=42}")
166+
bookmarkEnd = element("w:bookmarkEnd")
167+
168+
bookmark = _Bookmark((bookmarkStart, bookmarkEnd))
169+
170+
assert bookmark.id == 42
171+
164172
def it_knows_its_name(self):
165173
bookmarkStart = element("w:bookmarkStart{w:name=bmk-0}")
166174
bookmarkEnd = element("w:bookmarkEnd")

0 commit comments

Comments
 (0)