Skip to content

Commit

Permalink
refs #218: Added tests for rect tags missing get_style
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Ward committed May 23, 2016
1 parent 9a3ca88 commit 5ca4fb2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pydocx/test/document_builder.py
Expand Up @@ -19,6 +19,7 @@
'p': 'p.xml',
'pict': 'pict.xml',
'r': 'r.xml',
'rect': 'rect.xml',
'rpr': 'rpr.xml',
'sdt': 'sdt.xml',
'sectPr': 'sectPr.xml',
Expand Down Expand Up @@ -254,6 +255,16 @@ def pict(self, r_id=None, height=None, width=None):
width=width,
)

@classmethod
def rect(self, r_id=None, height=None, width=None):
template = env.get_template(templates['rect'])
return template_render(
template,
r_id=r_id,
height=height,
width=width,
)

@classmethod
def sectPr_tag(self, p_tag):
template = env.get_template(templates['sectPr'])
Expand Down
26 changes: 26 additions & 0 deletions tests/export/test_xml.py
Expand Up @@ -30,19 +30,29 @@ class ImageLocal(TranslationTestCase):
target_path='media/image2.jpeg',
data=b'content2',
),
dict(
relationship_id='rId2',
relationship_type=ImagePart.relationship_type,
external=False,
target_path='media/image3.jpeg',
data=b'content3',
),
]

expected_output = '''
<p><img src="data:image/jpeg;base64,Y29udGVudDE=" /></p>
<p><img src="data:image/jpeg;base64,Y29udGVudDI=" /></p>
<p><img src="data:image/jpeg;base64,Y29udGVudDM=" /></p>
'''

def get_xml(self):
drawing = DXB.drawing(height=None, width=None, r_id='rId0')
pict = DXB.pict(height=None, width=None, r_id='rId1')
rect = DXB.rect(height=None, width=None, r_id='rId2')
tags = [
drawing,
pict,
rect,
]
body = b''
for el in tags:
Expand All @@ -67,6 +77,13 @@ class ImageTestCase(TranslationTestCase):
target_path='media/image2.jpeg',
data=b'content2',
),
dict(
relationship_id='rId2',
relationship_type=ImagePart.relationship_type,
external=False,
target_path='media/image3.jpeg',
data=b'content3',
),
]

expected_output = '''
Expand All @@ -84,14 +101,23 @@ class ImageTestCase(TranslationTestCase):
width="41pt"
/>
</p>
<p>
<img
height="22pt"
src="data:image/jpeg;base64,Y29udGVudDM="
width="42pt"
/>
</p>
'''

def get_xml(self):
drawing = DXB.drawing(height=20, width=40, r_id='rId0')
pict = DXB.pict(height=21, width=41, r_id='rId1')
rect = DXB.rect(height=22, width=42, r_id='rId2')
tags = [
drawing,
pict,
rect,
]
body = b''
for el in tags:
Expand Down
18 changes: 18 additions & 0 deletions tests/templates/rect.xml
@@ -0,0 +1,18 @@
<w:p w:rsidR="00E94BDC" w:rsidRPr="003638EA" w:rsidRDefault="00E94BDC" w:rsidP="00E94BDC">
<w:pPr>
<w:rPr>
<w:color w:val="000000"/>
</w:rPr>
</w:pPr>
<w:r w:rsidR="00360165">
<w:rPr>
<w:color w:val="000000"/>
</w:rPr>
<w:pict>
<v:rect {%if width or height %}style="{% if width %}width:{{ width }}pt;{%endif%}{% if height %}height:{{ height }}pt{%endif%}"{% endif %}>

{% if r_id %}<v:imagedata r:id="{{ r_id }}" o:title="New Picture"/>{% endif %}
</v:rect>
</w:pict>
</w:r>
</w:p>

0 comments on commit 5ca4fb2

Please sign in to comment.