|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +Step implementations for paragraph-related features |
| 5 | +""" |
| 6 | + |
| 7 | +from behave import given, then |
| 8 | + |
| 9 | +from docx import Document |
| 10 | +from docx.text.tabstops import TabStop |
| 11 | + |
| 12 | +from helpers import test_docx |
| 13 | + |
| 14 | + |
| 15 | +# given =================================================== |
| 16 | + |
| 17 | +@given('a tab_stops having {count} tab stops') |
| 18 | +def given_a_tab_stops_having_count_tab_stops(context, count): |
| 19 | + paragraph_idx = {'0': 0, '3': 1}[count] |
| 20 | + document = Document(test_docx('tab-stops')) |
| 21 | + paragraph_format = document.paragraphs[paragraph_idx].paragraph_format |
| 22 | + context.tab_stops = paragraph_format.tab_stops |
| 23 | + |
| 24 | + |
| 25 | +# then ===================================================== |
| 26 | + |
| 27 | +@then('I can access a tab stop by index') |
| 28 | +def then_I_can_access_a_tab_stop_by_index(context): |
| 29 | + tab_stops = context.tab_stops |
| 30 | + for idx in range(3): |
| 31 | + tab_stop = tab_stops[idx] |
| 32 | + assert isinstance(tab_stop, TabStop) |
| 33 | + |
| 34 | + |
| 35 | +@then('I can iterate the TabStops object') |
| 36 | +def then_I_can_iterate_the_TabStops_object(context): |
| 37 | + items = [ts for ts in context.tab_stops] |
| 38 | + assert len(items) == 3 |
| 39 | + assert all(isinstance(item, TabStop) for item in items) |
| 40 | + |
| 41 | + |
| 42 | +@then('len(tab_stops) is {count}') |
| 43 | +def then_len_tab_stops_is_count(context, count): |
| 44 | + tab_stops = context.tab_stops |
| 45 | + assert len(tab_stops) == int(count) |
0 commit comments