File tree Expand file tree Collapse file tree 4 files changed +45
-3
lines changed
Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Original file line number Diff line number Diff line change 1414
1515from docx .oxml .base import register_custom_element_class
1616from docx .oxml .parts import CT_Body
17- from docx .oxml .text import CT_P
17+ from docx .oxml .text import CT_P , CT_R
1818
1919
2020# ===========================================================================
2323
2424register_custom_element_class ('w:body' , CT_Body )
2525register_custom_element_class ('w:p' , CT_P )
26+ register_custom_element_class ('w:r' , CT_R )
Original file line number Diff line number Diff line change @@ -32,3 +32,16 @@ def new():
3232 xml = '<w:p %s/>' % nsdecls ('w' )
3333 p = oxml_fromstring (xml )
3434 return p
35+
36+
37+ class CT_R (OxmlBaseElement ):
38+ """
39+ ``<w:r>`` element, containing the properties and text for a run.
40+ """
41+ @staticmethod
42+ def new ():
43+ """
44+ Return a new ``<w:r>`` element.
45+ """
46+ xml = '<w:r %s/>' % nsdecls ('w' )
47+ return oxml_fromstring (xml )
Original file line number Diff line number Diff line change 99
1010"""Test suite for the docx.oxml.text module."""
1111
12- from docx .oxml .text import CT_P
12+ from docx .oxml .text import CT_P , CT_R
1313
14- from ..unitdata import a_p
14+ from ..unitdata import a_p , an_r
1515
1616
1717class DescribeCT_P (object ):
@@ -20,3 +20,10 @@ def it_can_construct_a_new_p_element(self):
2020 p = CT_P .new ()
2121 expected_xml = a_p ().with_nsdecls ().xml
2222 assert p .xml == expected_xml
23+
24+
25+ class DescribeCT_R (object ):
26+
27+ def it_can_construct_a_new_r_element (self ):
28+ r = CT_R .new ()
29+ assert r .xml == an_r ().with_nsdecls ().xml
Original file line number Diff line number Diff line change @@ -101,6 +101,22 @@ def xml(self):
101101 return xml
102102
103103
104+ class CT_RBuilder (BaseBuilder ):
105+ """
106+ Test data builder for a CT_R (<w:r>) XML element that appears within the
107+ body element of a document.xml file.
108+ """
109+ def __init__ (self ):
110+ """Establish instance variables with default values"""
111+ super (CT_RBuilder , self ).__init__ ()
112+
113+ @property
114+ def xml (self ):
115+ """Return element XML based on attribute settings"""
116+ indent = ' ' * self ._indent
117+ return '%s<w:r%s/>\n ' % (indent , self ._nsdecls )
118+
119+
104120class CT_SectPrBuilder (BaseBuilder ):
105121 """
106122 Test data builder for a CT_SectPr (<w:sectPr>) XML element that appears
@@ -131,3 +147,8 @@ def a_p():
131147def a_sectPr ():
132148 """Return a CT_SectPr instance"""
133149 return CT_SectPrBuilder ()
150+
151+
152+ def an_r ():
153+ """Return a CT_RBuilder instance"""
154+ return CT_RBuilder ()
You can’t perform that action at this time.
0 commit comments