blob: 62705c9bcaf7a0f3522b374afee096ac8e3f3aff [file] [log] [blame]
Lars Gustäbel96753b32000-09-24 12:24:24 +00001# regression test for SAX 2.0
2# $Id$
3
Martin v. Löwis80670bc2000-10-06 21:13:23 +00004from xml.sax import make_parser, ContentHandler, \
5 SAXException, SAXReaderNotAvailable, SAXParseException
Martin v. Löwis962c9e72000-10-06 17:41:52 +00006try:
7 make_parser()
Martin v. Löwis80670bc2000-10-06 21:13:23 +00008except SAXReaderNotAvailable:
Martin v. Löwis962c9e72000-10-06 17:41:52 +00009 # don't try to test this module if we cannot create a parser
10 raise ImportError("no XML parsers available")
Fred Drakeacd32d32001-07-19 16:10:15 +000011from xml.sax.saxutils import XMLGenerator, escape, quoteattr, XMLFilterBase
Lars Gustäbel96753b32000-09-24 12:24:24 +000012from xml.sax.expatreader import create_parser
Lars Gustäbelb7536d52000-09-24 18:53:56 +000013from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
Lars Gustäbel96753b32000-09-24 12:24:24 +000014from cStringIO import StringIO
Marc-André Lemburg36619082001-01-17 19:11:13 +000015from test_support import verify, verbose, TestFailed, findfile
Lars Gustäbel96753b32000-09-24 12:24:24 +000016
17# ===== Utilities
18
19tests = 0
20fails = 0
21
22def confirm(outcome, name):
23 global tests, fails
24
25 tests = tests + 1
26 if outcome:
27 print "Passed", name
28 else:
29 print "Failed", name
30 fails = fails + 1
31
Lars Gustäbel2fc52942000-10-24 15:35:07 +000032def test_make_parser2():
Tim Petersd2bf3b72001-01-18 02:22:22 +000033 try:
Lars Gustäbel2fc52942000-10-24 15:35:07 +000034 # Creating parsers several times in a row should succeed.
35 # Testing this because there have been failures of this kind
36 # before.
37 from xml.sax import make_parser
38 p = make_parser()
39 from xml.sax import make_parser
40 p = make_parser()
41 from xml.sax import make_parser
42 p = make_parser()
43 from xml.sax import make_parser
44 p = make_parser()
45 from xml.sax import make_parser
46 p = make_parser()
47 from xml.sax import make_parser
48 p = make_parser()
49 except:
50 return 0
51 else:
52 return p
Tim Petersd2bf3b72001-01-18 02:22:22 +000053
54
Lars Gustäbel96753b32000-09-24 12:24:24 +000055# ===========================================================================
56#
57# saxutils tests
58#
59# ===========================================================================
60
61# ===== escape
62
63def test_escape_basic():
64 return escape("Donald Duck & Co") == "Donald Duck & Co"
65
66def test_escape_all():
67 return escape("<Donald Duck & Co>") == "&lt;Donald Duck &amp; Co&gt;"
68
69def test_escape_extra():
70 return escape("Hei på deg", {"å" : "&aring;"}) == "Hei p&aring; deg"
71
Fred Drakeacd32d32001-07-19 16:10:15 +000072# ===== quoteattr
73
74def test_quoteattr_basic():
75 return quoteattr("Donald Duck & Co") == '"Donald Duck &amp; Co"'
76
77def test_single_quoteattr():
78 return (quoteattr('Includes "double" quotes')
79 == '\'Includes "double" quotes\'')
80
81def test_double_quoteattr():
82 return (quoteattr("Includes 'single' quotes")
83 == "\"Includes 'single' quotes\"")
84
85def test_single_double_quoteattr():
86 return (quoteattr("Includes 'single' and \"double\" quotes")
87 == "\"Includes 'single' and &quot;double&quot; quotes\"")
88
89# ===== make_parser
90
Martin v. Löwis962c9e72000-10-06 17:41:52 +000091def test_make_parser():
92 try:
93 # Creating a parser should succeed - it should fall back
94 # to the expatreader
95 p = make_parser(['xml.parsers.no_such_parser'])
96 except:
97 return 0
98 else:
99 return p
100
101
Lars Gustäbel96753b32000-09-24 12:24:24 +0000102# ===== XMLGenerator
103
104start = '<?xml version="1.0" encoding="iso-8859-1"?>\n'
105
106def test_xmlgen_basic():
107 result = StringIO()
108 gen = XMLGenerator(result)
109 gen.startDocument()
110 gen.startElement("doc", {})
111 gen.endElement("doc")
112 gen.endDocument()
113
114 return result.getvalue() == start + "<doc></doc>"
115
116def test_xmlgen_content():
117 result = StringIO()
118 gen = XMLGenerator(result)
Fred Drake004d5e62000-10-23 17:22:08 +0000119
Lars Gustäbel96753b32000-09-24 12:24:24 +0000120 gen.startDocument()
121 gen.startElement("doc", {})
122 gen.characters("huhei")
123 gen.endElement("doc")
124 gen.endDocument()
125
126 return result.getvalue() == start + "<doc>huhei</doc>"
127
128def test_xmlgen_pi():
129 result = StringIO()
130 gen = XMLGenerator(result)
Fred Drake004d5e62000-10-23 17:22:08 +0000131
Lars Gustäbel96753b32000-09-24 12:24:24 +0000132 gen.startDocument()
133 gen.processingInstruction("test", "data")
134 gen.startElement("doc", {})
135 gen.endElement("doc")
136 gen.endDocument()
137
138 return result.getvalue() == start + "<?test data?><doc></doc>"
139
140def test_xmlgen_content_escape():
141 result = StringIO()
142 gen = XMLGenerator(result)
Fred Drake004d5e62000-10-23 17:22:08 +0000143
Lars Gustäbel96753b32000-09-24 12:24:24 +0000144 gen.startDocument()
145 gen.startElement("doc", {})
146 gen.characters("<huhei&")
147 gen.endElement("doc")
148 gen.endDocument()
149
150 return result.getvalue() == start + "<doc>&lt;huhei&amp;</doc>"
151
152def test_xmlgen_ignorable():
153 result = StringIO()
154 gen = XMLGenerator(result)
Fred Drake004d5e62000-10-23 17:22:08 +0000155
Lars Gustäbel96753b32000-09-24 12:24:24 +0000156 gen.startDocument()
157 gen.startElement("doc", {})
158 gen.ignorableWhitespace(" ")
159 gen.endElement("doc")
160 gen.endDocument()
161
162 return result.getvalue() == start + "<doc> </doc>"
163
164ns_uri = "http://www.python.org/xml-ns/saxtest/"
165
166def test_xmlgen_ns():
167 result = StringIO()
168 gen = XMLGenerator(result)
Fred Drake004d5e62000-10-23 17:22:08 +0000169
Lars Gustäbel96753b32000-09-24 12:24:24 +0000170 gen.startDocument()
171 gen.startPrefixMapping("ns1", ns_uri)
Lars Gustäbel6a7768a2000-09-27 08:12:17 +0000172 gen.startElementNS((ns_uri, "doc"), "ns1:doc", {})
Martin v. Löwiscf0a1cc2000-10-03 22:35:29 +0000173 # add an unqualified name
174 gen.startElementNS((None, "udoc"), None, {})
175 gen.endElementNS((None, "udoc"), None)
Lars Gustäbel6a7768a2000-09-27 08:12:17 +0000176 gen.endElementNS((ns_uri, "doc"), "ns1:doc")
Lars Gustäbel96753b32000-09-24 12:24:24 +0000177 gen.endPrefixMapping("ns1")
178 gen.endDocument()
179
Martin v. Löwiscf0a1cc2000-10-03 22:35:29 +0000180 return result.getvalue() == start + \
181 ('<ns1:doc xmlns:ns1="%s"><udoc></udoc></ns1:doc>' %
Lars Gustäbel96753b32000-09-24 12:24:24 +0000182 ns_uri)
183
184# ===== XMLFilterBase
185
186def test_filter_basic():
187 result = StringIO()
188 gen = XMLGenerator(result)
189 filter = XMLFilterBase()
190 filter.setContentHandler(gen)
Fred Drake004d5e62000-10-23 17:22:08 +0000191
Lars Gustäbel96753b32000-09-24 12:24:24 +0000192 filter.startDocument()
193 filter.startElement("doc", {})
194 filter.characters("content")
195 filter.ignorableWhitespace(" ")
196 filter.endElement("doc")
197 filter.endDocument()
198
199 return result.getvalue() == start + "<doc>content </doc>"
200
201# ===========================================================================
202#
203# expatreader tests
204#
205# ===========================================================================
206
Lars Gustäbel07025072000-10-24 16:00:22 +0000207# ===== XMLReader support
208
209def test_expat_file():
210 parser = create_parser()
211 result = StringIO()
212 xmlgen = XMLGenerator(result)
213
214 parser.setContentHandler(xmlgen)
215 parser.parse(open(findfile("test.xml")))
216
217 return result.getvalue() == xml_test_out
218
Lars Gustäbel96753b32000-09-24 12:24:24 +0000219# ===== DTDHandler support
220
221class TestDTDHandler:
222
223 def __init__(self):
224 self._notations = []
225 self._entities = []
Fred Drake004d5e62000-10-23 17:22:08 +0000226
Lars Gustäbel96753b32000-09-24 12:24:24 +0000227 def notationDecl(self, name, publicId, systemId):
228 self._notations.append((name, publicId, systemId))
229
230 def unparsedEntityDecl(self, name, publicId, systemId, ndata):
231 self._entities.append((name, publicId, systemId, ndata))
232
Lars Gustäbele292a242000-09-24 20:19:45 +0000233def test_expat_dtdhandler():
234 parser = create_parser()
235 handler = TestDTDHandler()
236 parser.setDTDHandler(handler)
Lars Gustäbel96753b32000-09-24 12:24:24 +0000237
Lars Gustäbele292a242000-09-24 20:19:45 +0000238 parser.feed('<!DOCTYPE doc [\n')
239 parser.feed(' <!ENTITY img SYSTEM "expat.gif" NDATA GIF>\n')
240 parser.feed(' <!NOTATION GIF PUBLIC "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN">\n')
241 parser.feed(']>\n')
242 parser.feed('<doc></doc>')
243 parser.close()
Lars Gustäbel96753b32000-09-24 12:24:24 +0000244
Lars Gustäbele292a242000-09-24 20:19:45 +0000245 return handler._notations == [("GIF", "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN", None)] and \
246 handler._entities == [("img", None, "expat.gif", "GIF")]
Lars Gustäbel96753b32000-09-24 12:24:24 +0000247
248# ===== EntityResolver support
249
Lars Gustäbele292a242000-09-24 20:19:45 +0000250class TestEntityResolver:
Lars Gustäbel96753b32000-09-24 12:24:24 +0000251
Lars Gustäbele292a242000-09-24 20:19:45 +0000252 def resolveEntity(self, publicId, systemId):
253 inpsrc = InputSource()
254 inpsrc.setByteStream(StringIO("<entity/>"))
255 return inpsrc
256
257def test_expat_entityresolver():
Lars Gustäbele292a242000-09-24 20:19:45 +0000258 parser = create_parser()
259 parser.setEntityResolver(TestEntityResolver())
260 result = StringIO()
261 parser.setContentHandler(XMLGenerator(result))
262
263 parser.feed('<!DOCTYPE doc [\n')
264 parser.feed(' <!ENTITY test SYSTEM "whatever">\n')
265 parser.feed(']>\n')
266 parser.feed('<doc>&test;</doc>')
267 parser.close()
268
269 return result.getvalue() == start + "<doc><entity></entity></doc>"
Fred Drake004d5e62000-10-23 17:22:08 +0000270
Lars Gustäbelab647872000-09-24 18:40:52 +0000271# ===== Attributes support
272
273class AttrGatherer(ContentHandler):
274
275 def startElement(self, name, attrs):
276 self._attrs = attrs
277
278 def startElementNS(self, name, qname, attrs):
279 self._attrs = attrs
Fred Drake004d5e62000-10-23 17:22:08 +0000280
Lars Gustäbelab647872000-09-24 18:40:52 +0000281def test_expat_attrs_empty():
282 parser = create_parser()
283 gather = AttrGatherer()
284 parser.setContentHandler(gather)
285
286 parser.feed("<doc/>")
287 parser.close()
288
289 return verify_empty_attrs(gather._attrs)
290
291def test_expat_attrs_wattr():
292 parser = create_parser()
293 gather = AttrGatherer()
294 parser.setContentHandler(gather)
295
296 parser.feed("<doc attr='val'/>")
297 parser.close()
298
299 return verify_attrs_wattr(gather._attrs)
300
301def test_expat_nsattrs_empty():
302 parser = create_parser(1)
303 gather = AttrGatherer()
304 parser.setContentHandler(gather)
305
306 parser.feed("<doc/>")
307 parser.close()
308
309 return verify_empty_nsattrs(gather._attrs)
310
311def test_expat_nsattrs_wattr():
312 parser = create_parser(1)
313 gather = AttrGatherer()
314 parser.setContentHandler(gather)
315
316 parser.feed("<doc xmlns:ns='%s' ns:attr='val'/>" % ns_uri)
317 parser.close()
318
319 attrs = gather._attrs
Fred Drake004d5e62000-10-23 17:22:08 +0000320
Lars Gustäbelab647872000-09-24 18:40:52 +0000321 return attrs.getLength() == 1 and \
322 attrs.getNames() == [(ns_uri, "attr")] and \
323 attrs.getQNames() == [] and \
324 len(attrs) == 1 and \
325 attrs.has_key((ns_uri, "attr")) and \
326 attrs.keys() == [(ns_uri, "attr")] and \
327 attrs.get((ns_uri, "attr")) == "val" and \
328 attrs.get((ns_uri, "attr"), 25) == "val" and \
329 attrs.items() == [((ns_uri, "attr"), "val")] and \
330 attrs.values() == ["val"] and \
331 attrs.getValue((ns_uri, "attr")) == "val" and \
332 attrs[(ns_uri, "attr")] == "val"
333
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000334# ===== InputSource support
335
Martin v. Löwis33315b12000-09-24 20:30:24 +0000336xml_test_out = open(findfile("test.xml.out")).read()
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000337
338def test_expat_inpsource_filename():
339 parser = create_parser()
340 result = StringIO()
341 xmlgen = XMLGenerator(result)
342
343 parser.setContentHandler(xmlgen)
Martin v. Löwis33315b12000-09-24 20:30:24 +0000344 parser.parse(findfile("test.xml"))
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000345
346 return result.getvalue() == xml_test_out
347
348def test_expat_inpsource_sysid():
349 parser = create_parser()
350 result = StringIO()
351 xmlgen = XMLGenerator(result)
352
353 parser.setContentHandler(xmlgen)
Martin v. Löwis33315b12000-09-24 20:30:24 +0000354 parser.parse(InputSource(findfile("test.xml")))
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000355
356 return result.getvalue() == xml_test_out
357
358def test_expat_inpsource_stream():
359 parser = create_parser()
360 result = StringIO()
361 xmlgen = XMLGenerator(result)
362
363 parser.setContentHandler(xmlgen)
364 inpsrc = InputSource()
Martin v. Löwis33315b12000-09-24 20:30:24 +0000365 inpsrc.setByteStream(open(findfile("test.xml")))
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000366 parser.parse(inpsrc)
367
368 return result.getvalue() == xml_test_out
369
Lars Gustäbel2fc52942000-10-24 15:35:07 +0000370# ===== IncrementalParser support
371
372def test_expat_incremental():
373 result = StringIO()
374 xmlgen = XMLGenerator(result)
375 parser = create_parser()
376 parser.setContentHandler(xmlgen)
377
378 parser.feed("<doc>")
379 parser.feed("</doc>")
380 parser.close()
381
382 return result.getvalue() == start + "<doc></doc>"
383
384def test_expat_incremental_reset():
385 result = StringIO()
386 xmlgen = XMLGenerator(result)
387 parser = create_parser()
388 parser.setContentHandler(xmlgen)
389
390 parser.feed("<doc>")
391 parser.feed("text")
392
393 result = StringIO()
394 xmlgen = XMLGenerator(result)
395 parser.setContentHandler(xmlgen)
396 parser.reset()
397
398 parser.feed("<doc>")
399 parser.feed("text")
400 parser.feed("</doc>")
401 parser.close()
402
403 return result.getvalue() == start + "<doc>text</doc>"
404
405# ===== Locator support
406
407def test_expat_locator_noinfo():
408 result = StringIO()
409 xmlgen = XMLGenerator(result)
410 parser = create_parser()
411 parser.setContentHandler(xmlgen)
412
413 parser.feed("<doc>")
414 parser.feed("</doc>")
415 parser.close()
416
Fred Drake132dce22000-12-12 23:11:42 +0000417 return parser.getSystemId() is None and \
418 parser.getPublicId() is None and \
Tim Petersd2bf3b72001-01-18 02:22:22 +0000419 parser.getLineNumber() == 1
Lars Gustäbel2fc52942000-10-24 15:35:07 +0000420
421def test_expat_locator_withinfo():
422 result = StringIO()
423 xmlgen = XMLGenerator(result)
424 parser = create_parser()
425 parser.setContentHandler(xmlgen)
426 parser.parse(findfile("test.xml"))
427
428 return parser.getSystemId() == findfile("test.xml") and \
Fred Drake132dce22000-12-12 23:11:42 +0000429 parser.getPublicId() is None
Lars Gustäbel2fc52942000-10-24 15:35:07 +0000430
Martin v. Löwis80670bc2000-10-06 21:13:23 +0000431
432# ===========================================================================
433#
434# error reporting
435#
436# ===========================================================================
437
438def test_expat_inpsource_location():
439 parser = create_parser()
440 parser.setContentHandler(ContentHandler()) # do nothing
441 source = InputSource()
442 source.setByteStream(StringIO("<foo bar foobar>")) #ill-formed
443 name = "a file name"
444 source.setSystemId(name)
445 try:
446 parser.parse(source)
447 except SAXException, e:
448 return e.getSystemId() == name
449
450def test_expat_incomplete():
451 parser = create_parser()
452 parser.setContentHandler(ContentHandler()) # do nothing
453 try:
454 parser.parse(StringIO("<foo>"))
455 except SAXParseException:
456 return 1 # ok, error found
457 else:
458 return 0
459
460
Lars Gustäbelab647872000-09-24 18:40:52 +0000461# ===========================================================================
462#
463# xmlreader tests
464#
465# ===========================================================================
466
467# ===== AttributesImpl
468
469def verify_empty_attrs(attrs):
470 try:
471 attrs.getValue("attr")
472 gvk = 0
473 except KeyError:
474 gvk = 1
475
476 try:
477 attrs.getValueByQName("attr")
478 gvqk = 0
479 except KeyError:
480 gvqk = 1
481
482 try:
483 attrs.getNameByQName("attr")
484 gnqk = 0
485 except KeyError:
486 gnqk = 1
487
488 try:
489 attrs.getQNameByName("attr")
490 gqnk = 0
491 except KeyError:
492 gqnk = 1
Fred Drake004d5e62000-10-23 17:22:08 +0000493
Lars Gustäbelab647872000-09-24 18:40:52 +0000494 try:
495 attrs["attr"]
496 gik = 0
497 except KeyError:
498 gik = 1
Fred Drake004d5e62000-10-23 17:22:08 +0000499
Lars Gustäbelab647872000-09-24 18:40:52 +0000500 return attrs.getLength() == 0 and \
501 attrs.getNames() == [] and \
502 attrs.getQNames() == [] and \
503 len(attrs) == 0 and \
504 not attrs.has_key("attr") and \
505 attrs.keys() == [] and \
Fred Drake132dce22000-12-12 23:11:42 +0000506 attrs.get("attrs") is None and \
Lars Gustäbelab647872000-09-24 18:40:52 +0000507 attrs.get("attrs", 25) == 25 and \
508 attrs.items() == [] and \
509 attrs.values() == [] and \
510 gvk and gvqk and gnqk and gik and gqnk
511
512def verify_attrs_wattr(attrs):
513 return attrs.getLength() == 1 and \
514 attrs.getNames() == ["attr"] and \
515 attrs.getQNames() == ["attr"] and \
516 len(attrs) == 1 and \
517 attrs.has_key("attr") and \
518 attrs.keys() == ["attr"] and \
519 attrs.get("attr") == "val" and \
520 attrs.get("attr", 25) == "val" and \
521 attrs.items() == [("attr", "val")] and \
522 attrs.values() == ["val"] and \
523 attrs.getValue("attr") == "val" and \
524 attrs.getValueByQName("attr") == "val" and \
525 attrs.getNameByQName("attr") == "attr" and \
526 attrs["attr"] == "val" and \
527 attrs.getQNameByName("attr") == "attr"
528
529def test_attrs_empty():
530 return verify_empty_attrs(AttributesImpl({}))
531
532def test_attrs_wattr():
533 return verify_attrs_wattr(AttributesImpl({"attr" : "val"}))
534
535# ===== AttributesImpl
536
537def verify_empty_nsattrs(attrs):
538 try:
539 attrs.getValue((ns_uri, "attr"))
540 gvk = 0
541 except KeyError:
542 gvk = 1
543
544 try:
545 attrs.getValueByQName("ns:attr")
546 gvqk = 0
547 except KeyError:
548 gvqk = 1
549
550 try:
551 attrs.getNameByQName("ns:attr")
552 gnqk = 0
553 except KeyError:
554 gnqk = 1
555
556 try:
557 attrs.getQNameByName((ns_uri, "attr"))
558 gqnk = 0
559 except KeyError:
560 gqnk = 1
Fred Drake004d5e62000-10-23 17:22:08 +0000561
Lars Gustäbelab647872000-09-24 18:40:52 +0000562 try:
563 attrs[(ns_uri, "attr")]
564 gik = 0
565 except KeyError:
566 gik = 1
Fred Drake004d5e62000-10-23 17:22:08 +0000567
Lars Gustäbelab647872000-09-24 18:40:52 +0000568 return attrs.getLength() == 0 and \
569 attrs.getNames() == [] and \
570 attrs.getQNames() == [] and \
571 len(attrs) == 0 and \
572 not attrs.has_key((ns_uri, "attr")) and \
573 attrs.keys() == [] and \
Fred Drake132dce22000-12-12 23:11:42 +0000574 attrs.get((ns_uri, "attr")) is None and \
Lars Gustäbelab647872000-09-24 18:40:52 +0000575 attrs.get((ns_uri, "attr"), 25) == 25 and \
576 attrs.items() == [] and \
577 attrs.values() == [] and \
578 gvk and gvqk and gnqk and gik and gqnk
579
580def test_nsattrs_empty():
581 return verify_empty_nsattrs(AttributesNSImpl({}, {}))
582
583def test_nsattrs_wattr():
584 attrs = AttributesNSImpl({(ns_uri, "attr") : "val"},
585 {(ns_uri, "attr") : "ns:attr"})
Fred Drake004d5e62000-10-23 17:22:08 +0000586
Lars Gustäbelab647872000-09-24 18:40:52 +0000587 return attrs.getLength() == 1 and \
588 attrs.getNames() == [(ns_uri, "attr")] and \
589 attrs.getQNames() == ["ns:attr"] and \
590 len(attrs) == 1 and \
591 attrs.has_key((ns_uri, "attr")) and \
592 attrs.keys() == [(ns_uri, "attr")] and \
593 attrs.get((ns_uri, "attr")) == "val" and \
594 attrs.get((ns_uri, "attr"), 25) == "val" and \
595 attrs.items() == [((ns_uri, "attr"), "val")] and \
596 attrs.values() == ["val"] and \
597 attrs.getValue((ns_uri, "attr")) == "val" and \
598 attrs.getValueByQName("ns:attr") == "val" and \
599 attrs.getNameByQName("ns:attr") == (ns_uri, "attr") and \
600 attrs[(ns_uri, "attr")] == "val" and \
601 attrs.getQNameByName((ns_uri, "attr")) == "ns:attr"
Fred Drake004d5e62000-10-23 17:22:08 +0000602
Lars Gustäbelab647872000-09-24 18:40:52 +0000603
Lars Gustäbel96753b32000-09-24 12:24:24 +0000604# ===== Main program
605
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000606def make_test_output():
607 parser = create_parser()
608 result = StringIO()
609 xmlgen = XMLGenerator(result)
610
611 parser.setContentHandler(xmlgen)
Martin v. Löwis33315b12000-09-24 20:30:24 +0000612 parser.parse(findfile("test.xml"))
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000613
Martin v. Löwis33315b12000-09-24 20:30:24 +0000614 outf = open(findfile("test.xml.out"), "w")
Lars Gustäbelb7536d52000-09-24 18:53:56 +0000615 outf.write(result.getvalue())
616 outf.close()
617
Lars Gustäbel96753b32000-09-24 12:24:24 +0000618items = locals().items()
619items.sort()
620for (name, value) in items:
621 if name[ : 5] == "test_":
622 confirm(value(), name)
623
624print "%d tests, %d failures" % (tests, fails)
625if fails != 0:
626 raise TestFailed, "%d of %d tests failed" % (fails, tests)