Added test script for TemplateError trapping

This commit is contained in:
Jonathan Pyle 2018-08-06 22:04:00 -04:00
parent 3b221fb0c6
commit 0a3627d23a
3 changed files with 15 additions and 0 deletions

15
tests/template_error.py Normal file
View File

@ -0,0 +1,15 @@
from docxtpl import DocxTemplate, RichText
from jinja2.exceptions import TemplateError
try:
tpl = DocxTemplate('test_files/template_error_tpl.docx')
tpl.render({
'test_variable' : 'test variable value'
})
except TemplateError as the_error:
print unicode(the_error)
if hasattr(the_error, 'docx_context'):
print "Context:"
for line in the_error.docx_context:
print line
tpl.save('test_files/template_error.docx')

Binary file not shown.

Binary file not shown.