Permalink
Browse files

refs #20: added tests for smart tag (and insert since it wasnt tested…

…) and links with multiple runs
  • Loading branch information...
1 parent d3c0eb2 commit 46d9cf3a2572f0cd00d4145d27190710f0fcffcb @jlward jlward committed Mar 21, 2013
@@ -3,16 +3,18 @@
templates = {
'drawing': 'drawing.xml',
'hyperlink': 'hyperlink.xml',
+ 'insert': 'insert.xml',
'main': 'base.xml',
'p': 'p.xml',
'pict': 'pict.xml',
'r': 'r.xml',
'sectPr': 'sectPr.xml',
+ 'smartTag': 'smart_tag.xml',
+ 'style': 'style.xml',
+ 'styles': 'styles.xml',
'table': 'table.xml',
'tc': 'tc.xml',
'tr': 'tr.xml',
- 'styles': 'styles.xml',
- 'style': 'style.xml',
}
env = Environment(
@@ -65,6 +67,22 @@ def hyperlink_tag(self, r_id, run_tags):
return template.render(**kwargs)
@classmethod
+ def insert_tag(self, run_tags):
+ template = env.get_template(templates['insert'])
+ kwargs = {
+ 'run_tags': run_tags,
+ }
+ return template.render(**kwargs)
+
+ @classmethod
+ def smart_tag(self, run_tags):
+ template = env.get_template(templates['smartTag'])
+ kwargs = {
+ 'run_tags': run_tags,
+ }
+ return template.render(**kwargs)
+
+ @classmethod
def li(self, text, ilvl, numId, bold=False):
if isinstance(text, str):
# Use create a single r tag based on the text and the bold
@@ -0,0 +1,5 @@
+<w:ins>
+ {% for run_tag in run_tags %}
+ {{ run_tag }}
+ {% endfor %}
+</w:ins>
@@ -0,0 +1,5 @@
+<w:smartTag>
+ {% for run_tag in run_tags %}
+ {{ run_tag }}
+ {% endfor %}
+</w:smartTag>
@@ -443,6 +443,25 @@ def get_xml(self):
return etree.fromstring(xml)
+class NonStandardTextTagsTestCase(_TranslationTestCase):
+ expected_output = '''
+ <html>
+ <p>insert smarttag</p>
+ </html>
+ '''
+
+ def get_xml(self):
+ run_tags = [DXB.r_tag(i) for i in 'insert ']
+ insert_tag = DXB.insert_tag(run_tags)
+ run_tags = [DXB.r_tag(i) for i in 'smarttag']
+ smart_tag = DXB.smart_tag(run_tags)
+
+ run_tags = [insert_tag, smart_tag]
+ body = DXB.p_tag(run_tags)
+ xml = DXB.xml(body)
+ return etree.fromstring(xml)
+
+
class HyperlinkStyledTestCase(_TranslationTestCase):
relationship_dict = {
'rId0': 'www.google.com',
@@ -464,6 +483,26 @@ def get_xml(self):
return etree.fromstring(xml)
+class HyperlinkWithMultipleRunsTestCase(_TranslationTestCase):
+ relationship_dict = {
+ 'rId0': 'www.google.com',
+ }
+
+ expected_output = '''
+ <html>
+ <p><a href="www.google.com">link</a>.</p>
+ </html>
+ '''
+
+ def get_xml(self):
+ run_tags = [DXB.r_tag(i) for i in 'link']
+ run_tags = [DXB.hyperlink_tag(r_id='rId0', run_tags=run_tags)]
+ run_tags.append(DXB.r_tag('.', is_bold=False))
+ body = DXB.p_tag(run_tags)
+ xml = DXB.xml(body)
+ return etree.fromstring(xml)
+
+
class HyperlinkNoTextTestCase(_TranslationTestCase):
relationship_dict = {
'rId0': 'www.google.com',

0 comments on commit 46d9cf3

Please sign in to comment.