######################################################################## # $Header: /var/local/cvsroot/4Suite/test/Xml/Xslt/Exslt/test_common.py,v 1.5 2005/10/09 02:09:26 mbrown Exp $ """Tests for EXSLT Common""" from Xml.Xslt import test_harness import tempfile, os from Ft.Lib import Uri SRC1 = """""" SRC2 = """\ """ TESTS = [] # exsl:node-set() def test_NodeSet(tester): sheet_1 = """ """ expected_1 = '1 eggs' # 4XSLT used to die a horrible death when computing the union of # two node-sets that were created with exslt:node-set(). sheet_2 = """\ """ expected_2 = """ """ sheet_3 = """\ """ expected_3 = """ """ sheet_4 = """\ """ expected_4 = expected_3 sheet_5 = """\ """ expected_5 = """ foo""" source = test_harness.FileInfo(string=SRC1) sheet = test_harness.FileInfo(string=sheet_1) test_harness.XsltTest(tester, source, [sheet], expected_1, title='exsl:node-set()') source = test_harness.FileInfo(string=SRC1) sheet = test_harness.FileInfo(string=sheet_2) test_harness.XsltTest(tester, source, [sheet], expected_2, title='exsl:node-set() union 1') source = test_harness.FileInfo(string=SRC1) sheet = test_harness.FileInfo(string=sheet_3) test_harness.XsltTest(tester, source, [sheet], expected_3, title='exsl:node-set() union 2') source = test_harness.FileInfo(string=SRC2) sheet = test_harness.FileInfo(string=sheet_4) test_harness.XsltTest(tester, source, [sheet], expected_4, title='exsl:node-set() union 3') source = test_harness.FileInfo(string=SRC2) sheet = test_harness.FileInfo(string=sheet_5) test_harness.XsltTest(tester, source, [sheet], expected_5, title='exsl:node-set() on string arg') return TESTS.append(test_NodeSet) # exsl:object-type() def test_ObjectType(tester): sheet_1 = """\ """ expected_1 = "RTF node-set string number boolean" source = test_harness.FileInfo(string=SRC1) sheet = test_harness.FileInfo(string=sheet_1) test_harness.XsltTest(tester, source, [sheet], expected_1, title='exsl:object-type()') return TESTS.append(test_ObjectType) # def test_Document(tester): sty = """\ Writing data file test """ src = """\ 11 12 13 14 15 """ expected = """ Writing data file 11 Writing data file 12 Writing data file 13 Writing data file 14 Writing data file 15 """ file_xml_indented = """ %s test """ file_xml = """ %stest""" file_html_indented = """ %s test """ file_html = """%stest""" tester.startGroup("exsl:document") fileName = tempfile.mktemp() fileUri = Uri.OsPathToUri(fileName) source = test_harness.FileInfo(string=src) sheet = test_harness.FileInfo(string=sty) for method, indent, file_expected in (('xml', 'yes', file_xml_indented), ('xml', 'no', file_xml), ('html', 'yes', file_html_indented), ('html', 'no', file_html)): title="Using method='%s', indent='%s'" % (method, indent) test_harness.XsltTest(tester, source, [sheet], expected, topLevelParams={'filebase' : fileUri, 'method' : method, 'indent' : indent}, title=title) tester.startTest("Checking output documents") for data in range(11, 16): file_name = '%s%d.xml' % (fileName, data) tester.compare(True, os.path.exists(file_name)) file = open(file_name, 'r') fileData = file.read() file.close() tester.compare(file_expected % data, fileData) if os.path.exists(file_name): os.unlink(file_name) tester.testDone() #-------- title = ('cdata-section-elements in secondary document') src = """document.write('<p>foo & bar</p>')""" sty = """ test

test

""" expected = """ test

test

""" expected_filedata = """ document.write('<p>foo & bar</p>')""" fileName = tempfile.mktemp() fileUri = Uri.OsPathToUri(fileName) main = 'method="html" indent="yes" encoding="iso-8859-1"' secondary = 'method="xml" encoding="utf-8" indent="no" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" cdata-section-elements="xhtml:script"' sheet_str = sty % {'main': main, 'secondary': secondary, 'outfile': fileUri} source = test_harness.FileInfo(string=src) sheet = test_harness.FileInfo(string=sheet_str) test_harness.XsltTest(tester, source, [sheet], expected, title=title) tester.compare(True, os.path.exists(fileName)) file = open(fileName, 'r') fileData = file.read() file.close() tester.compare(expected_filedata, fileData) if os.path.exists(fileName): os.unlink(fileName) title = 'cdata-section-elements in main document only' fileName = tempfile.mktemp() fileUri = Uri.OsPathToUri(fileName) main = 'method="html" indent="yes" encoding="iso-8859-1" cdata-section-elements="xhtml:script"' secondary = 'method="xml" encoding="utf-8" indent="no" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"' sheet_str = sty % {'main': main, 'secondary': secondary, 'outfile': fileUri} source = test_harness.FileInfo(string=src) sheet = test_harness.FileInfo(string=sheet_str) test_harness.XsltTest(tester, source, [sheet], expected, title=title) expected_filedata = """ document.write('<p>foo & bar</p>')""" file = open(fileName, 'r') fileData = file.read() file.close() tester.compare(expected_filedata, fileData) if os.path.exists(fileName): os.unlink(fileName) tester.groupDone() return TESTS.append(test_Document) def Test(tester): tester.startGroup('Common') for test in TESTS: test(tester) tester.groupDone() return