Now using Travis-CI to automatize the tests, some changes to make tests pass in python3.3
This commit is contained in:
parent
0eccef32bf
commit
5f7b240aa6
3 changed files with 18 additions and 6 deletions
7
.travis.yml
Normal file
7
.travis.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
language: python
|
||||||
|
python:
|
||||||
|
- "2.6"
|
||||||
|
- "2.7"
|
||||||
|
- "3.3"
|
||||||
|
install: "python setup.py develop"
|
||||||
|
script: "python setup.py test"
|
||||||
14
secretary.py
14
secretary.py
|
|
@ -32,11 +32,12 @@ the jinja2 template engine. To render a template:
|
||||||
engine = Render(template_file)
|
engine = Render(template_file)
|
||||||
result = engine.render(template_var1=...)
|
result = engine.render(template_var1=...)
|
||||||
"""
|
"""
|
||||||
|
from __future__ import unicode_literals, print_function
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
import zipfile
|
||||||
import StringIO
|
import io
|
||||||
from xml.dom.minidom import parseString
|
from xml.dom.minidom import parseString
|
||||||
from jinja2 import Environment, Undefined
|
from jinja2 import Environment, Undefined
|
||||||
|
|
||||||
|
|
@ -45,7 +46,7 @@ class UndefinedSilently(Undefined):
|
||||||
# Silently undefined,
|
# Silently undefined,
|
||||||
# see http://stackoverflow.com/questions/6182498/jinja2-how-to-make-it-fail-silently-like-djangotemplate
|
# see http://stackoverflow.com/questions/6182498/jinja2-how-to-make-it-fail-silently-like-djangotemplate
|
||||||
def silently_undefined(*args, **kwargs):
|
def silently_undefined(*args, **kwargs):
|
||||||
return u''
|
return ''
|
||||||
|
|
||||||
return_new = lambda *args, **kwargs: UndefinedSilently()
|
return_new = lambda *args, **kwargs: UndefinedSilently()
|
||||||
|
|
||||||
|
|
@ -118,13 +119,14 @@ class Render(object):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pack_document(self):
|
def pack_document(self):
|
||||||
"""
|
"""
|
||||||
Make an archive from _unpacked_template
|
Make an archive from _unpacked_template
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Save rendered content and headers
|
# Save rendered content and headers
|
||||||
self.rendered = StringIO.StringIO()
|
self.rendered = io.BytesIO()
|
||||||
|
|
||||||
with zipfile.ZipFile(self.rendered, 'a') as packed_template:
|
with zipfile.ZipFile(self.rendered, 'a') as packed_template:
|
||||||
for filename, content in self.file_list.items():
|
for filename, content in self.file_list.items():
|
||||||
|
|
@ -141,6 +143,7 @@ class Render(object):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def render(self, **kwargs):
|
def render(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Unpack and render the internal template and
|
Unpack and render the internal template and
|
||||||
|
|
@ -230,6 +233,7 @@ class Render(object):
|
||||||
parent.removeChild(field)
|
parent.removeChild(field)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def render_template(template, **kwargs):
|
def render_template(template, **kwargs):
|
||||||
"""
|
"""
|
||||||
Render a ODF template file
|
Render a ODF template file
|
||||||
|
|
@ -250,7 +254,7 @@ if __name__ == "__main__":
|
||||||
{'country': 'United States', 'capital': 'Washington', 'cities': ['miami', 'new york', 'california', 'texas', 'atlanta']},
|
{'country': 'United States', 'capital': 'Washington', 'cities': ['miami', 'new york', 'california', 'texas', 'atlanta']},
|
||||||
{'country': 'England', 'capital': 'London', 'cities': ['gales']},
|
{'country': 'England', 'capital': 'London', 'cities': ['gales']},
|
||||||
{'country': 'Japan', 'capital': 'Tokio', 'cities': ['hiroshima', 'nagazaki']},
|
{'country': 'Japan', 'capital': 'Tokio', 'cities': ['hiroshima', 'nagazaki']},
|
||||||
{'country': 'Nicaragua', 'capital': 'Managua', 'cities': [u'león', 'granada', 'masaya']},
|
{'country': 'Nicaragua', 'capital': 'Managua', 'cities': ['león', 'granada', 'masaya']},
|
||||||
{'country': 'Argentina', 'capital': 'Buenos aires'},
|
{'country': 'Argentina', 'capital': 'Buenos aires'},
|
||||||
{'country': 'Chile', 'capital': 'Santiago'},
|
{'country': 'Chile', 'capital': 'Santiago'},
|
||||||
{'country': 'Mexico', 'capital': 'MExico City', 'cities': ['puebla', 'cancun']},
|
{'country': 'Mexico', 'capital': 'MExico City', 'cities': ['puebla', 'cancun']},
|
||||||
|
|
@ -263,4 +267,4 @@ if __name__ == "__main__":
|
||||||
output = open('rendered.odt', 'w')
|
output = open('rendered.odt', 'w')
|
||||||
output.write(result)
|
output.write(result)
|
||||||
|
|
||||||
print "Template rendering finished! Check rendered.odt file."
|
print("Template rendering finished! Check rendered.odt file.")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from xml.dom.minidom import getDOMImplementation
|
from xml.dom.minidom import getDOMImplementation
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
@ -9,7 +11,6 @@ def test_undefined_silently():
|
||||||
|
|
||||||
assert isinstance(undefined(), UndefinedSilently)
|
assert isinstance(undefined(), UndefinedSilently)
|
||||||
assert isinstance(undefined.attribute, UndefinedSilently)
|
assert isinstance(undefined.attribute, UndefinedSilently)
|
||||||
assert unicode(undefined) == u''
|
|
||||||
assert str(undefined) == ''
|
assert str(undefined) == ''
|
||||||
|
|
||||||
def test_pad_string():
|
def test_pad_string():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue