Skip to content

Commit c88125c

Browse files
author
Steve Canny
committed
parfmt: add ParagraphFormat.alignment setter
1 parent a076932 commit c88125c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

docx/text/paragraph.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,8 @@ def alignment(self):
149149
if pPr is None:
150150
return None
151151
return pPr.jc_val
152+
153+
@alignment.setter
154+
def alignment(self, value):
155+
pPr = self._element.get_or_add_pPr()
156+
pPr.jc_val = value

features/txt-parfmt-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Feature: Get or set paragraph formatting properties
1515
| right | WD_ALIGN_PARAGRAPH.RIGHT |
1616

1717

18-
@wip
1918
Scenario Outline: Set paragraph alignment
2019
Given a paragraph format having <align-type> alignment
2120
When I assign <new-value> to paragraph_format.alignment

tests/text/test_paragraph.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ def it_knows_its_alignment_value(self, alignment_get_fixture):
291291
paragraph_format, expected_value = alignment_get_fixture
292292
assert paragraph_format.alignment == expected_value
293293

294+
def it_can_change_its_alignment_value(self, alignment_set_fixture):
295+
paragraph_format, value, expected_xml = alignment_set_fixture
296+
paragraph_format.alignment = value
297+
assert paragraph_format._element.xml == expected_xml
298+
294299
# fixtures -------------------------------------------------------
295300

296301
@pytest.fixture(params=[
@@ -302,3 +307,21 @@ def alignment_get_fixture(self, request):
302307
p_cxml, expected_value = request.param
303308
paragraph_format = ParagraphFormat(element(p_cxml))
304309
return paragraph_format, expected_value
310+
311+
@pytest.fixture(params=[
312+
('w:p', WD_ALIGN_PARAGRAPH.LEFT,
313+
'w:p/w:pPr/w:jc{w:val=left}'),
314+
('w:p/w:pPr', WD_ALIGN_PARAGRAPH.CENTER,
315+
'w:p/w:pPr/w:jc{w:val=center}'),
316+
('w:p/w:pPr/w:jc{w:val=center}', WD_ALIGN_PARAGRAPH.RIGHT,
317+
'w:p/w:pPr/w:jc{w:val=right}'),
318+
('w:p/w:pPr/w:jc{w:val=right}', None,
319+
'w:p/w:pPr'),
320+
('w:p', None,
321+
'w:p/w:pPr'),
322+
])
323+
def alignment_set_fixture(self, request):
324+
p_cxml, value, expected_cxml = request.param
325+
paragraph_format = ParagraphFormat(element(p_cxml))
326+
expected_xml = xml(expected_cxml)
327+
return paragraph_format, value, expected_xml

0 commit comments

Comments
 (0)