Skip to content

Commit 2be2c92

Browse files
author
Steve Canny
committed
acpt: add scenarios for ParagraphFormat.alignment
1 parent 37788b0 commit 2be2c92

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed
1.3 KB
Binary file not shown.

features/steps/text.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from behave import given, then, when
1212

1313
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
1515
from docx.oxml import parse_xml
1616
from docx.oxml.ns import nsdecls, qn
1717
from docx.text.run import Font, Run
@@ -65,6 +65,17 @@ def given_a_font_of_size(context, size):
6565
context.font = document.styles[style_name].font
6666

6767

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+
6879
@given('a run')
6980
def given_a_run(context):
7081
document = Document()
@@ -235,6 +246,17 @@ def when_I_assign_value_to_font_sub_super(context, value_key, sub_super):
235246
setattr(font, name, value)
236247

237248

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+
238260
@when('I assign {value_str} to its {bool_prop_name} property')
239261
def when_assign_true_to_bool_run_prop(context, value_str, bool_prop_name):
240262
value = {'True': True, 'False': False, 'None': None}[value_str]
@@ -327,6 +349,18 @@ def then_type_is_page_break(context):
327349
assert attrib == {qn('w:type'): 'page'}
328350

329351

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+
330364
@then('run.font is the Font object for the run')
331365
def then_run_font_is_the_Font_object_for_the_run(context):
332366
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
@@ -0,0 +1,29 @@
1+
Feature: Get or set paragraph formatting properties
2+
In order to customize the formatting of paragraphs in a document
3+
As a python-docx developer
4+
I need a ParagraphFormat object with read/write formatting properties
5+
6+
7+
@wip
8+
Scenario Outline: Get paragraph alignment
9+
Given a paragraph format having <align-type> alignment
10+
Then paragraph_format.alignment is <value>
11+
12+
Examples: paragraph_format.alignment values
13+
| align-type | value |
14+
| inherited | None |
15+
| center | WD_ALIGN_PARAGRAPH.CENTER |
16+
| right | WD_ALIGN_PARAGRAPH.RIGHT |
17+
18+
19+
@wip
20+
Scenario Outline: Set paragraph alignment
21+
Given a paragraph format having <align-type> alignment
22+
When I assign <new-value> to paragraph_format.alignment
23+
Then paragraph_format.alignment is <value>
24+
25+
Examples: paragraph_format.alignment assignment results
26+
| align-type | new-value | value |
27+
| inherited | WD_ALIGN_PARAGRAPH.CENTER | WD_ALIGN_PARAGRAPH.CENTER |
28+
| center | WD_ALIGN_PARAGRAPH.RIGHT | WD_ALIGN_PARAGRAPH.RIGHT |
29+
| right | None | None |

0 commit comments

Comments
 (0)