6 sys.path.append("python")
10 # the testsuite description
12 CONF="xml-test-suite/xmlconf/xmlconf.xml"
13 LOG="check-xml-test-suite.log"
18 # Error and warning handlers
22 def errorHandler(ctx, str):
26 if string.find(str, "error:") >= 0:
27 error_nr = error_nr + 1
28 if len(error_msg) < 300:
29 if len(error_msg) == 0 or error_msg[-1] == '\n':
30 error_msg = error_msg + " >>" + str
32 error_msg = error_msg + str
34 libxml2.registerErrorHandler(errorHandler, None)
38 #def warningHandler(ctx, str):
42 # warning_nr = warning_nr + 1
43 # warning = warning + str
45 #libxml2.registerWarningHandler(warningHandler, None)
48 # Used to load the XML testsuite description
50 def loadNoentDoc(filename):
51 ctxt = libxml2.createFileParserCtxt(filename)
54 ctxt.replaceEntities(1)
60 if ctxt.wellFormed() != 1:
66 # The conformance testing routines
69 def testNotWf(filename, id):
77 ctxt = libxml2.createFileParserCtxt(filename)
86 if error_nr == 0 or ctxt.wellFormed() != 0:
87 print "%s: error: Well Formedness error not detected" % (id)
88 log.write("%s: error: Well Formedness error not detected\n" % (id))
93 def testNotWfEnt(filename, id):
101 ctxt = libxml2.createFileParserCtxt(filename)
104 ctxt.replaceEntities(1)
111 if error_nr == 0 or ctxt.wellFormed() != 0:
112 print "%s: error: Well Formedness error not detected" % (id)
113 log.write("%s: error: Well Formedness error not detected\n" % (id))
118 def testNotWfEntDtd(filename, id):
126 ctxt = libxml2.createFileParserCtxt(filename)
129 ctxt.replaceEntities(1)
137 if error_nr == 0 or ctxt.wellFormed() != 0:
138 print "%s: error: Well Formedness error not detected" % (id)
139 log.write("%s: error: Well Formedness error not detected\n" % (id))
144 def testWfEntDtd(filename, id):
152 ctxt = libxml2.createFileParserCtxt(filename)
155 ctxt.replaceEntities(1)
163 if ctxt.wellFormed() == 0:
164 print "%s: error: wrongly failed to parse the document" % (id)
165 log.write("%s: error: wrongly failed to parse the document\n" % (id))
168 print "%s: warning: WF document generated an error msg" % (id)
169 log.write("%s: error: WF document generated an error msg\n" % (id))
175 def testError(filename, id):
183 ctxt = libxml2.createFileParserCtxt(filename)
186 ctxt.replaceEntities(1)
194 if ctxt.wellFormed() == 0:
195 print "%s: warning: failed to parse the document but accepted" % (id)
196 log.write("%s: warning: failed to parse the document but accepte\n" % (id))
199 print "%s: warning: WF document generated an error msg" % (id)
200 log.write("%s: error: WF document generated an error msg\n" % (id))
206 def testInvalid(filename, id):
214 ctxt = libxml2.createFileParserCtxt(filename)
224 valid = ctxt.isValid()
226 print "%s: error: wrongly failed to parse the document" % (id)
227 log.write("%s: error: wrongly failed to parse the document\n" % (id))
230 print "%s: error: Validity error not detected" % (id)
231 log.write("%s: error: Validity error not detected\n" % (id))
235 print "%s: warning: Validity error not reported" % (id)
236 log.write("%s: warning: Validity error not reported\n" % (id))
243 def testValid(filename, id):
250 ctxt = libxml2.createFileParserCtxt(filename)
260 valid = ctxt.isValid()
262 print "%s: error: wrongly failed to parse the document" % (id)
263 log.write("%s: error: wrongly failed to parse the document\n" % (id))
266 print "%s: error: Validity check failed" % (id)
267 log.write("%s: error: Validity check failed\n" % (id))
270 if error_nr != 0 or valid != 1:
271 print "%s: warning: valid document reported an error" % (id)
272 log.write("%s: warning: valid document reported an error\n" % (id))
290 uri = test.prop('URI')
293 print "Test without ID:", uri
296 print "Test without URI:", id
298 base = test.getBase(None)
299 URI = libxml2.buildURI(uri, base)
300 if os.access(URI, os.R_OK) == 0:
301 print "Test %s missing: base %s uri %s" % (URI, base, uri)
303 type = test.prop('TYPE')
305 print "Test %s missing TYPE" % (id)
309 if type == "invalid":
310 res = testInvalid(URI, id)
311 elif type == "valid":
312 res = testValid(URI, id)
313 elif type == "not-wf":
314 extra = test.prop('ENTITIES')
317 # res = testNotWfEntDtd(URI, id)
318 #elif extra == 'none':
319 # res = testNotWf(URI, id)
320 #elif extra == 'general':
321 # res = testNotWfEnt(URI, id)
322 #elif extra == 'both' or extra == 'parameter':
323 res = testNotWfEntDtd(URI, id)
325 # print "Unknow value %s for an ENTITIES test value" % (extra)
327 elif type == "error":
328 res = testError(URI, id)
330 # TODO skipped for now
333 test_nr = test_nr + 1
335 test_succeed = test_succeed + 1
337 test_failed = test_failed + 1
339 test_error = test_error + 1
343 log.write(" File: %s\n" % (URI))
344 content = string.strip(test.content)
345 while content[-1] == '\n':
346 content = content[0:-1]
348 log.write(" %s:%s:%s\n" % (type, extra, content))
350 log.write(" %s:%s\n\n" % (type, content))
352 log.write(" ----\n%s ----\n" % (error_msg))
359 def runTestCases(case):
360 profile = case.prop('PROFILE')
361 if profile != None and \
362 string.find(profile, "IBM XML Conformance Test Suite - Production") < 0:
366 if test.name == 'TEST':
368 if test.name == 'TESTCASES':
372 conf = loadNoentDoc(CONF)
374 print "Unable to load %s" % CONF
377 testsuite = conf.getRootElement()
378 if testsuite.name != 'TESTSUITE':
379 print "Expecting TESTSUITE root element: aborting"
382 profile = testsuite.prop('PROFILE')
388 case = testsuite.children
395 if case.name == 'TESTCASES':
396 old_test_nr = test_nr
397 old_test_succeed = test_succeed
398 old_test_failed = test_failed
399 old_test_error = test_error
401 print " Ran %d tests: %d suceeded, %d failed and %d generated an error" % (
402 test_nr - old_test_nr, test_succeed - old_test_succeed,
403 test_failed - old_test_failed, test_error - old_test_error)
409 print "Ran %d tests: %d suceeded, %d failed and %d generated an error in %.2f s." % (
410 test_nr, test_succeed, test_failed, test_error, time.time() - start)