|
| 1 | +# encoding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +Step implementations for text-related features |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import absolute_import, print_function, unicode_literals |
| 8 | + |
| 9 | +from behave import given, then, when |
| 10 | + |
| 11 | +from docx import Document |
| 12 | + |
| 13 | + |
| 14 | +# given =================================================== |
| 15 | + |
| 16 | +@given('a run') |
| 17 | +def given_a_run(context): |
| 18 | + p = Document().body.paragraphs[0] |
| 19 | + context.run = p.add_run() |
| 20 | + |
| 21 | + |
| 22 | +# when ==================================================== |
| 23 | + |
| 24 | +@when('I add a line break') |
| 25 | +def when_add_line_break(context): |
| 26 | + run = context.run |
| 27 | + run.add_break() |
| 28 | + |
| 29 | + |
| 30 | +# then ===================================================== |
| 31 | + |
| 32 | +@then('the last item in the run is a break') |
| 33 | +def then_last_item_in_run_is_a_break(context): |
| 34 | + run = context.run |
| 35 | + context.last_child = run._r[-1] |
| 36 | + expected_tag = ( |
| 37 | + '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}br' |
| 38 | + ) |
| 39 | + assert context.last_child.tag == expected_tag |
| 40 | + |
| 41 | + |
| 42 | +@then('it is a line break') |
| 43 | +def then_type_is_line_break(context): |
| 44 | + attrib = context.last_child.attrib |
| 45 | + assert attrib == {} |
| 46 | + |
| 47 | + |
| 48 | +@then('it is a page break') |
| 49 | +def then_type_is_page_break(context): |
| 50 | + attrib = context.last_child.attrib |
| 51 | + assert attrib == {'type': 'page'} |
| 52 | + |
| 53 | + |
| 54 | +@then('it is a column break') |
| 55 | +def then_type_is_column_break(context): |
| 56 | + attrib = context.last_child.attrib |
| 57 | + assert attrib == {'type': 'column'} |
0 commit comments