Skip to content

Commit e8de57e

Browse files
author
Steve Canny
committed
acpt: add scenarios for ParagraphFormat spacing
1 parent c88125c commit e8de57e

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

features/steps/text.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from docx.enum.text import WD_ALIGN_PARAGRAPH, WD_BREAK, WD_UNDERLINE
1515
from docx.oxml import parse_xml
1616
from docx.oxml.ns import nsdecls, qn
17+
from docx.shared import Pt
1718
from docx.text.run import Font, Run
1819

1920
from helpers import test_docx, test_file, test_text
@@ -65,6 +66,13 @@ def given_a_font_of_size(context, size):
6566
context.font = document.styles[style_name].font
6667

6768

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+
6876
@given('a paragraph format having {type} alignment')
6977
def given_a_paragraph_format_having_align_type_alignment(context, type):
7078
style_name = {
@@ -257,6 +265,18 @@ def when_I_assign_value_to_paragraph_format_alignment(context, value_key):
257265
paragraph_format.alignment = value
258266

259267

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+
260280
@when('I assign {value_str} to its {bool_prop_name} property')
261281
def when_assign_true_to_bool_run_prop(context, value_str, bool_prop_name):
262282
value = {'True': True, 'False': False, 'None': None}[value_str]
@@ -361,6 +381,15 @@ def then_paragraph_format_alignment_is_value(context, value_key):
361381
assert paragraph_format.alignment == value
362382

363383

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+
364393
@then('run.font is the Font object for the run')
365394
def then_run_font_is_the_Font_object_for_the_run(context):
366395
run, font = context.run, context.run.font

features/txt-parfmt-props.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,32 @@ Feature: Get or set paragraph formatting properties
2525
| inherited | WD_ALIGN_PARAGRAPH.CENTER | WD_ALIGN_PARAGRAPH.CENTER |
2626
| center | WD_ALIGN_PARAGRAPH.RIGHT | WD_ALIGN_PARAGRAPH.RIGHT |
2727
| right | None | None |
28+
29+
30+
@wip
31+
Scenario Outline: Get paragraph spacing
32+
Given a paragraph format having <setting> space <side>
33+
Then paragraph_format.space_<side> is <value>
34+
35+
Examples: paragraph_format spacing values
36+
| side | setting | value |
37+
| before | inherited | None |
38+
| before | 24 pt | 304800 |
39+
| after | inherited | None |
40+
| after | 42 pt | 533400 |
41+
42+
43+
@wip
44+
Scenario Outline: Set paragraph spacing
45+
Given a paragraph format having <setting> space <side>
46+
When I assign <new-value> to paragraph_format.space_<side>
47+
Then paragraph_format.space_<side> is <value>
48+
49+
Examples: paragraph_format spacing assignment results
50+
| side | setting | new-value | value |
51+
| before | inherited | Pt(12) | 152400 |
52+
| before | 24 pt | Pt(18) | 228600 |
53+
| before | 24 pt | None | None |
54+
| after | inherited | Pt(12) | 152400 |
55+
| after | 42 pt | Pt(18) | 228600 |
56+
| after | 42 pt | None | None |

0 commit comments

Comments
 (0)