Skip to content
This repository was archived by the owner on Jan 7, 2024. It is now read-only.

Commit d7f2bef

Browse files
onlyjusSteve Canny
authored andcommitted
acpt: add par-alignment-prop.feature
with scenario for read/write Paragraph.alignment property
1 parent 38aeb63 commit d7f2bef

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Get or set paragraph alignment
2+
In order to specify the justification of a paragraph
3+
As a python-docx developer
4+
I need a read/write alignment property on paragraph objects
5+
6+
7+
@wip
8+
Scenario Outline: Get paragraph alignment
9+
Given a paragraph having <align-type> alignment
10+
Then the paragraph alignment property value is <align-value>
11+
12+
Examples: align property values
13+
| align-type | align-value |
14+
| inherited | None |
15+
| left | WD_ALIGN_PARAGRAPH.LEFT |
16+
| center | WD_ALIGN_PARAGRAPH.CENTER |
17+
| right | WD_ALIGN_PARAGRAPH.RIGHT |

features/steps/paragraph.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
from behave import given, then, when
88

99
from docx import Document
10+
from docx.enum.text import WD_ALIGN_PARAGRAPH
1011
from docx.oxml import parse_xml
1112
from docx.oxml.ns import nsdecls
1213
from docx.text import Paragraph
1314

14-
from helpers import saved_docx_path, test_text
15+
from helpers import saved_docx_path, test_docx, test_text
1516

1617

1718
TEST_STYLE = 'Heading1'
@@ -28,6 +29,19 @@ def given_a_document_containing_three_paragraphs(context):
2829
context.document = document
2930

3031

32+
@given('a paragraph having {align_type} alignment')
33+
def given_a_paragraph_align_type_alignment(context, align_type):
34+
paragraph_idx = {
35+
'inherited': 0,
36+
'left': 1,
37+
'center': 2,
38+
'right': 3,
39+
'justified': 4,
40+
}[align_type]
41+
document = Document(test_docx('par-alignment'))
42+
context.paragraph = document.paragraphs[paragraph_idx]
43+
44+
3145
@given('a paragraph with content and formatting')
3246
def given_a_paragraph_with_content_and_formatting(context):
3347
p_xml = """\
@@ -88,6 +102,17 @@ def then_document_contains_text_I_added(context):
88102
assert r.text == test_text
89103

90104

105+
@then('the paragraph alignment property value is {align_value}')
106+
def then_the_paragraph_alignment_prop_value_is_value(context, align_value):
107+
expected_value = {
108+
'None': None,
109+
'WD_ALIGN_PARAGRAPH.LEFT': WD_ALIGN_PARAGRAPH.LEFT,
110+
'WD_ALIGN_PARAGRAPH.CENTER': WD_ALIGN_PARAGRAPH.CENTER,
111+
'WD_ALIGN_PARAGRAPH.RIGHT': WD_ALIGN_PARAGRAPH.RIGHT,
112+
}[align_value]
113+
assert context.paragraph.alignment == expected_value
114+
115+
91116
@then('the paragraph formatting is preserved')
92117
def then_the_paragraph_formatting_is_preserved(context):
93118
assert context.paragraph.style == TEST_STYLE
14.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)