🌐 AI搜索 & 代理 主页
Skip to content

Commit e092fee

Browse files
Benjamin Toornstrascanny
authored andcommitted
acpt: add scenarios for Bookmarks
1 parent 7419161 commit e092fee

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

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 3 as bookmarks
10+
Then len(bookmarks) == 3
11+
And bookmarks[1] is a Bookmark object
12+
And iterating bookmarks produces 3 Bookmark objects

features/steps/bookmarks.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 3 as bookmarks')
19+
def given_a_Bookmarks_object_of_length_3_as_bookmarks(context):
20+
document = Document(test_docx('bmk-bookmarks'))
21+
context.bookmarks = document.bookmarks
22+
23+
24+
# then =====================================================
25+
26+
@then('bookmarks[{idx_literal}] is a Bookmark object')
27+
def then_bookmarks_idx_is_a_Bookmark_object(context, idx_literal):
28+
idx = int(idx_literal)
29+
item = context.bookmarks[idx]
30+
expected = 'Bookmark'
31+
actual = item.__class__.__name__
32+
assert actual == expected, 'bookmarks[%s] == %s' % (idx, actual)
33+
34+
35+
@then('iterating bookmarks produces {n} Bookmark objects')
36+
def then_iterating_bookmarks_produces_n_Bookmark_objects(context, n):
37+
items = [item for item in context.bookmarks]
38+
assert len(items) == 3
39+
assert all(item.__class__.__name__ == 'Bookmark' for item in items)
40+
41+
42+
@then('len(bookmarks) == {count}')
43+
def then_len_bookmarks_eq_count(context, count):
44+
expected = int(count)
45+
actual = len(context.bookmarks)
46+
assert actual == expected, 'len(bookmarks) == %s' % actual
24.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)