Skip to content

Commit f7ade08

Browse files
author
Steve Canny
committed
oxml: add CT_PPr.new()
1 parent 6106096 commit f7ade08

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

docx/oxml/text.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ def __setattr__(self, attr, value):
7171
else:
7272
super(CT_PPr, self).__setattr__(attr, value)
7373

74+
@staticmethod
75+
def new():
76+
"""
77+
Return a new ``<w:pPr>`` element.
78+
"""
79+
xml = '<w:pPr %s/>' % nsdecls('w')
80+
pPr = oxml_fromstring(xml)
81+
return pPr
82+
7483
@property
7584
def style(self):
7685
"""

tests/oxml/test_text.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
"""Test suite for the docx.oxml.text module."""
1111

12-
from docx.oxml.text import CT_P, CT_R, CT_Text
12+
from docx.oxml.text import CT_P, CT_PPr, CT_R, CT_Text
1313

1414
from ..unitdata import a_p, a_pPr, a_t, an_r
1515

@@ -50,6 +50,11 @@ def it_knows_its_paragraph_style(self):
5050

5151
class DescribeCT_PPr(object):
5252

53+
def it_can_construct_a_new_pPr_element(self):
54+
pPr = CT_PPr.new()
55+
expected_xml = a_pPr().with_nsdecls().xml
56+
assert pPr.xml == expected_xml
57+
5358
def it_knows_the_paragraph_style(self):
5459
cases = (
5560
(a_pPr(), None),

0 commit comments

Comments
 (0)