Skip to content

Commit 80390ff

Browse files
author
Steve Canny
committed
text: add Paragraph.style setter
1 parent 08fe8b9 commit 80390ff

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

docx/text.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def style(self):
4343
style = self._p.style
4444
return style if style is not None else 'Normal'
4545

46+
@style.setter
47+
def style(self, style):
48+
self._p.style = None if style == 'Normal' else style
49+
4650

4751
class Run(object):
4852
"""

tests/test_text.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ def it_knows_its_paragraph_style(self):
5959
p = Paragraph(p_elm)
6060
assert p.style == expected_style
6161

62+
def it_can_set_its_paragraph_style(self):
63+
cases = (
64+
('foobar', 'foobar'),
65+
('Normal', None),
66+
)
67+
for style, expected_setting in cases:
68+
p_elm = Mock(name='p_elm')
69+
p = Paragraph(p_elm)
70+
p.style = style
71+
assert p_elm.style == expected_setting
72+
6273

6374
class DescribeRun(object):
6475

0 commit comments

Comments
 (0)