|
11 | 11 | from behave import given, then, when |
12 | 12 |
|
13 | 13 | from docx import Document |
14 | | -from docx.enum.text import WD_BREAK, WD_UNDERLINE |
| 14 | +from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_BREAK, WD_UNDERLINE |
15 | 15 | from docx.oxml import parse_xml |
16 | 16 | from docx.oxml.ns import nsdecls, qn |
17 | 17 | from docx.text.run import Font, Run |
@@ -65,6 +65,17 @@ def given_a_font_of_size(context, size): |
65 | 65 | context.font = document.styles[style_name].font |
66 | 66 |
|
67 | 67 |
|
| 68 | +@given('a paragraph format having {type} alignment') |
| 69 | +def given_a_paragraph_format_having_align_type_alignment(context, type): |
| 70 | + style_name = { |
| 71 | + 'inherited': 'Normal', |
| 72 | + 'center': 'Base', |
| 73 | + 'right': 'Citation', |
| 74 | + }[type] |
| 75 | + document = Document(test_docx('sty-known-styles')) |
| 76 | + context.paragraph_format = document.styles[style_name].paragraph_format |
| 77 | + |
| 78 | + |
68 | 79 | @given('a run') |
69 | 80 | def given_a_run(context): |
70 | 81 | document = Document() |
@@ -235,6 +246,17 @@ def when_I_assign_value_to_font_sub_super(context, value_key, sub_super): |
235 | 246 | setattr(font, name, value) |
236 | 247 |
|
237 | 248 |
|
| 249 | +@when('I assign {value_key} to paragraph_format.alignment') |
| 250 | +def when_I_assign_value_to_paragraph_format_alignment(context, value_key): |
| 251 | + value = { |
| 252 | + 'None': None, |
| 253 | + 'WD_ALIGN_PARAGRAPH.CENTER': WD_ALIGN_PARAGRAPH.CENTER, |
| 254 | + 'WD_ALIGN_PARAGRAPH.RIGHT': WD_ALIGN_PARAGRAPH.RIGHT, |
| 255 | + }[value_key] |
| 256 | + paragraph_format = context.paragraph_format |
| 257 | + paragraph_format.alignment = value |
| 258 | + |
| 259 | + |
238 | 260 | @when('I assign {value_str} to its {bool_prop_name} property') |
239 | 261 | def when_assign_true_to_bool_run_prop(context, value_str, bool_prop_name): |
240 | 262 | value = {'True': True, 'False': False, 'None': None}[value_str] |
@@ -327,6 +349,18 @@ def then_type_is_page_break(context): |
327 | 349 | assert attrib == {qn('w:type'): 'page'} |
328 | 350 |
|
329 | 351 |
|
| 352 | +@then('paragraph_format.alignment is {value_key}') |
| 353 | +def then_paragraph_format_alignment_is_value(context, value_key): |
| 354 | + value = { |
| 355 | + 'None': None, |
| 356 | + 'WD_ALIGN_PARAGRAPH.LEFT': WD_ALIGN_PARAGRAPH.LEFT, |
| 357 | + 'WD_ALIGN_PARAGRAPH.CENTER': WD_ALIGN_PARAGRAPH.CENTER, |
| 358 | + 'WD_ALIGN_PARAGRAPH.RIGHT': WD_ALIGN_PARAGRAPH.RIGHT, |
| 359 | + }[value_key] |
| 360 | + paragraph_format = context.paragraph_format |
| 361 | + assert paragraph_format.alignment == value |
| 362 | + |
| 363 | + |
330 | 364 | @then('run.font is the Font object for the run') |
331 | 365 | def then_run_font_is_the_Font_object_for_the_run(context): |
332 | 366 | run, font = context.run, context.run.font |
|
0 commit comments