Skip to content

Commit d16452e

Browse files
author
Steve Canny
committed
parfmt: add ParagraphFormat.space_after setter
1 parent bc296cf commit d16452e

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

docx/oxml/text/paragraph.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ def spacing_after(self):
139139
return None
140140
return spacing.after
141141

142+
@spacing_after.setter
143+
def spacing_after(self, value):
144+
if value is None and self.spacing is None:
145+
return
146+
self.get_or_add_spacing().after = value
147+
142148
@property
143149
def spacing_before(self):
144150
"""

docx/text/paragraph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ def space_after(self):
170170
return None
171171
return pPr.spacing_after
172172

173+
@space_after.setter
174+
def space_after(self, value):
175+
self._element.get_or_add_pPr().spacing_after = value
176+
173177
@property
174178
def space_before(self):
175179
"""

features/txt-parfmt-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Feature: Get or set paragraph formatting properties
3939
| after | 42 pt | 533400 |
4040

4141

42-
@wip
4342
Scenario Outline: Set paragraph spacing
4443
Given a paragraph format having <setting> space <side>
4544
When I assign <new-value> to paragraph_format.space_<side>

tests/text/test_paragraph.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ def it_knows_its_space_after(self, space_after_get_fixture):
310310
paragraph_format, expected_value = space_after_get_fixture
311311
assert paragraph_format.space_after == expected_value
312312

313+
def it_can_change_its_space_after(self, space_after_set_fixture):
314+
paragraph_format, value, expected_xml = space_after_set_fixture
315+
paragraph_format.space_after = value
316+
assert paragraph_format._element.xml == expected_xml
317+
313318
# fixtures -------------------------------------------------------
314319

315320
@pytest.fixture(params=[
@@ -351,6 +356,24 @@ def space_after_get_fixture(self, request):
351356
paragraph_format = ParagraphFormat(element(p_cxml))
352357
return paragraph_format, expected_value
353358

359+
@pytest.fixture(params=[
360+
('w:p', Pt(12), 'w:p/w:pPr/w:spacing{w:after=240}'),
361+
('w:p', None, 'w:p/w:pPr'),
362+
('w:p/w:pPr', Pt(12), 'w:p/w:pPr/w:spacing{w:after=240}'),
363+
('w:p/w:pPr', None, 'w:p/w:pPr'),
364+
('w:p/w:pPr/w:spacing', Pt(12), 'w:p/w:pPr/w:spacing{w:after=240}'),
365+
('w:p/w:pPr/w:spacing', None, 'w:p/w:pPr/w:spacing'),
366+
('w:p/w:pPr/w:spacing{w:after=240}', Pt(42),
367+
'w:p/w:pPr/w:spacing{w:after=840}'),
368+
('w:p/w:pPr/w:spacing{w:after=840}', None,
369+
'w:p/w:pPr/w:spacing'),
370+
])
371+
def space_after_set_fixture(self, request):
372+
p_cxml, value, expected_p_cxml = request.param
373+
paragraph_format = ParagraphFormat(element(p_cxml))
374+
expected_xml = xml(expected_p_cxml)
375+
return paragraph_format, value, expected_xml
376+
354377
@pytest.fixture(params=[
355378
('w:p', None),
356379
('w:p/w:pPr', None),

0 commit comments

Comments
 (0)