|
14 | 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 | +from docx.shared import Pt |
17 | 18 | from docx.text.run import Font, Run |
18 | 19 |
|
19 | 20 | from helpers import test_docx, test_file, test_text |
@@ -65,6 +66,13 @@ def given_a_font_of_size(context, size): |
65 | 66 | context.font = document.styles[style_name].font |
66 | 67 |
|
67 | 68 |
|
| 69 | +@given('a paragraph format having {setting} space {side}') |
| 70 | +def given_a_paragraph_format_having_setting_spacing(context, setting, side): |
| 71 | + style_name = 'Normal' if setting == 'inherited' else 'Base' |
| 72 | + document = Document(test_docx('sty-known-styles')) |
| 73 | + context.paragraph_format = document.styles[style_name].paragraph_format |
| 74 | + |
| 75 | + |
68 | 76 | @given('a paragraph format having {type} alignment') |
69 | 77 | def given_a_paragraph_format_having_align_type_alignment(context, type): |
70 | 78 | style_name = { |
@@ -257,6 +265,18 @@ def when_I_assign_value_to_paragraph_format_alignment(context, value_key): |
257 | 265 | paragraph_format.alignment = value |
258 | 266 |
|
259 | 267 |
|
| 268 | +@when('I assign {value_key} to paragraph_format.space_{side}') |
| 269 | +def when_I_assign_value_to_paragraph_format_space(context, value_key, side): |
| 270 | + paragraph_format = context.paragraph_format |
| 271 | + prop_name = 'space_%s' % side |
| 272 | + value = { |
| 273 | + 'None': None, |
| 274 | + 'Pt(12)': Pt(12), |
| 275 | + 'Pt(18)': Pt(18), |
| 276 | + }[value_key] |
| 277 | + setattr(paragraph_format, prop_name, value) |
| 278 | + |
| 279 | + |
260 | 280 | @when('I assign {value_str} to its {bool_prop_name} property') |
261 | 281 | def when_assign_true_to_bool_run_prop(context, value_str, bool_prop_name): |
262 | 282 | value = {'True': True, 'False': False, 'None': None}[value_str] |
@@ -361,6 +381,15 @@ def then_paragraph_format_alignment_is_value(context, value_key): |
361 | 381 | assert paragraph_format.alignment == value |
362 | 382 |
|
363 | 383 |
|
| 384 | +@then('paragraph_format.space_{side} is {value}') |
| 385 | +def then_paragraph_format_space_side_is_value(context, side, value): |
| 386 | + expected_value = None if value == 'None' else int(value) |
| 387 | + prop_name = 'space_%s' % side |
| 388 | + paragraph_format = context.paragraph_format |
| 389 | + actual_value = getattr(paragraph_format, prop_name) |
| 390 | + assert actual_value == expected_value |
| 391 | + |
| 392 | + |
364 | 393 | @then('run.font is the Font object for the run') |
365 | 394 | def then_run_font_is_the_Font_object_for_the_run(context): |
366 | 395 | run, font = context.run, context.run.font |
|
0 commit comments