Skip to content

Commit efbf649

Browse files
Benjamin Toornstrascanny
authored andcommitted
acpt: add scenario for Bookmarks
1 parent 758c98d commit efbf649

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

features/bmk-bookmarks.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: Access a bookmark
2+
In order to operate on document bookmark objects
3+
As a developer using python-docx
4+
I need sequence operations on Bookmarks
5+
6+
7+
@wip
8+
Scenario: Bookmarks is a sequence
9+
Given a Bookmarks object of length 5 as bookmarks
10+
Then len(bookmarks) == 5
11+
And bookmarks[1] is a _Bookmark object
12+
And iterating bookmarks produces 5 _Bookmark objects

features/steps/bookmarks.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# encoding: utf-8
2+
3+
"""Step implementations for bookmark-related features."""
4+
5+
from __future__ import (
6+
absolute_import, division, print_function, unicode_literals
7+
)
8+
9+
from behave import given, then
10+
11+
from docx import Document
12+
13+
from helpers import test_docx
14+
15+
16+
# given ===================================================
17+
18+
@given('a Bookmarks object of length 5 as bookmarks')
19+
def given_a_Bookmarks_object_of_length_5_as_bookmarks(context):
20+
document = Document(test_docx('bmk-bookmarks'))
21+
context.bookmarks = document.bookmarks
22+
23+
24+
# then =====================================================
25+
26+
@then('bookmarks[{idx}] is a _Bookmark object')
27+
def then_bookmarks_idx_is_a_Bookmark_object(context, idx):
28+
item = context.bookmarks[int(idx)]
29+
expected = '_Bookmark'
30+
actual = item.__class__.__name__
31+
assert actual == expected, 'bookmarks[%s] is a %s object' % (idx, actual)
32+
33+
34+
@then('iterating bookmarks produces {n} _Bookmark objects')
35+
def then_iterating_bookmarks_produces_n_Bookmark_objects(context, n):
36+
items = [item for item in context.bookmarks]
37+
assert len(items) == int(n)
38+
assert all(item.__class__.__name__ == '_Bookmark' for item in items)
39+
40+
41+
@then('len(bookmarks) == {count}')
42+
def then_len_bookmarks_eq_count(context, count):
43+
expected = int(count)
44+
actual = len(context.bookmarks)
45+
assert actual == expected, 'len(bookmarks) == %s' % actual
15.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)