-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathbookmarks.py
More file actions
64 lines (41 loc) · 1.88 KB
/
bookmarks.py
File metadata and controls
64 lines (41 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# encoding: utf-8
"""Step implementations for bookmark-related features."""
from __future__ import absolute_import, division, print_function, unicode_literals
from behave import given, then
from docx import Document
from helpers import test_docx
# given ===================================================
@given("a Bookmarks object of length 5 as bookmarks")
def given_a_Bookmarks_object_of_length_5_as_bookmarks(context):
document = Document(test_docx("bmk-bookmarks"))
context.bookmarks = document.bookmarks
# then =====================================================
@then("bookmark.id is an int")
def then_bookmark_id_is_an_int(context):
bookmark = context.bookmark
assert isinstance(bookmark.id, int)
@then('bookmark.name == "Target"')
def then_bookmark_name_eq_Target(context):
bookmark = context.bookmark
assert bookmark.name == "Target"
@then('bookmarks.get({name}) returns bookmark named "{name}" with id {id}')
def then_bookmark_get_returns_bookmark_object(context, name, id):
bookmark = context.bookmarks.get(name)
assert bookmark.name == name
assert bookmark.id == int(id)
@then("bookmarks[{idx}] is a _Bookmark object")
def then_bookmarks_idx_is_a_Bookmark_object(context, idx):
item = context.bookmarks[int(idx)]
expected = "_Bookmark"
actual = item.__class__.__name__
assert actual == expected, "bookmarks[%s] is a %s object" % (idx, actual)
@then("iterating bookmarks produces {n} _Bookmark objects")
def then_iterating_bookmarks_produces_n_Bookmark_objects(context, n):
items = [item for item in context.bookmarks]
assert len(items) == int(n)
assert all(item.__class__.__name__ == "_Bookmark" for item in items)
@then("len(bookmarks) == {count}")
def then_len_bookmarks_eq_count(context, count):
expected = int(count)
actual = len(context.bookmarks)
assert actual == expected, "len(bookmarks) == %s" % actual