import StringIO
import os
import Pyana
import unittest
import sys
parameterTestXSL = r'''
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:param name="p1"/>
<xsl:template match="/"><xsl:value-of select="$p1"/></xsl:template>
</xsl:stylesheet>
'''
parameterTests = [
({}, ''),
({'wrong': 5}, ''),
({'p1': '5+5'}, '10'),
({'p1': {}}, TypeError),
({'p1': 'blaf()'}, Pyana.XSLError),
({'p1': '((('}, Pyana.XSLError),
(None, TypeError),
('not dict', TypeError),
({'p1':'"Success!"'}, 'Success!'),
({'p1':u'"Success!"'}, 'Success!'),
({'p1':u'"Andr\u00e9e"'}, u'Andr\u00e9e'.encode('utf-8'))
]
class TopLevelParametersTestCase(unittest.TestCase):
def checkParameters(self):
t = Pyana.Transformer()
for args, expected in parameterTests:
try:
t.setStylesheetParams(args)
actual = t.transform2String(
'<a/>',
parameterTestXSL,
)
assert expected == actual
except Exception, e:
assert isinstance(e, expected)
# Convenience version
try:
actual = Pyana.transform2String(
'<a/>',
parameterTestXSL,
args
)
assert expected == actual
except Exception, e:
assert isinstance(e, expected)
def getTestSuites(type):
return unittest.TestSuite([
unittest.makeSuite(TopLevelParametersTestCase, type)
])
|