77from behave import given , then , when
88
99from docx import Document
10+ from docx .enum .text import WD_ALIGN_PARAGRAPH
1011from docx .oxml import parse_xml
1112from docx .oxml .ns import nsdecls
1213from 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
1718TEST_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' )
3246def 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' )
92117def then_the_paragraph_formatting_is_preserved (context ):
93118 assert context .paragraph .style == TEST_STYLE
0 commit comments