|
| 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 |
0 commit comments