summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sax.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2000-09-24 20:19:45 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2000-09-24 20:19:45 (GMT)
commite292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b (patch)
tree1b194ae63bc189cba2f8473de3a14059b614e273 /Lib/test/test_sax.py
parentbc1c1c98eb360e549663b1440a9c4f3d99d1d919 (diff)
downloadcpython-e292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b.zip
cpython-e292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b.tar.gz
cpython-e292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b.tar.bz2
Added EntityResolver and DTDHandler (patch 101631) with test cases.
Diffstat (limited to 'Lib/test/test_sax.py')
-rw-r--r--Lib/test/test_sax.py50
1 files changed, 34 insertions, 16 deletions
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
index 8ff3dac..46d0d3e 100644
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -156,25 +156,45 @@ class TestDTDHandler:
def unparsedEntityDecl(self, name, publicId, systemId, ndata):
self._entities.append((name, publicId, systemId, ndata))
-# def test_expat_dtdhandler():
-# parser = create_parser()
-# handler = TestDTDHandler()
-# parser.setDTDHandler(handler)
-
-# parser.feed('<!DOCTYPE doc [\n')
-# parser.feed(' <!ENTITY img SYSTEM "expat.gif" NDATA GIF>\n')
-# parser.feed(' <!NOTATION GIF PUBLIC "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN">\n')
-# parser.feed(']>\n')
-# parser.feed('<doc></doc>')
-# parser.close()
+def test_expat_dtdhandler():
+ parser = create_parser()
+ handler = TestDTDHandler()
+ parser.setDTDHandler(handler)
+
+ parser.feed('<!DOCTYPE doc [\n')
+ parser.feed(' <!ENTITY img SYSTEM "expat.gif" NDATA GIF>\n')
+ parser.feed(' <!NOTATION GIF PUBLIC "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN">\n')
+ parser.feed(']>\n')
+ parser.feed('<doc></doc>')
+ parser.close()
-# return handler._notations == [("GIF", "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN", None)] and \
-# handler._entities == [("img", None, "expat.gif", "GIF")]
+ return handler._notations == [("GIF", "-//CompuServe//NOTATION Graphics Interchange Format 89a//EN", None)] and \
+ handler._entities == [("img", None, "expat.gif", "GIF")]
# ===== EntityResolver support
-# can't test this until InputSource is in place
+class TestEntityResolver:
+ def resolveEntity(self, publicId, systemId):
+ inpsrc = InputSource()
+ inpsrc.setByteStream(StringIO("<entity/>"))
+ return inpsrc
+
+def test_expat_entityresolver():
+ return 1 # disabling this until pyexpat.c has been fixed
+ parser = create_parser()
+ parser.setEntityResolver(TestEntityResolver())
+ result = StringIO()
+ parser.setContentHandler(XMLGenerator(result))
+
+ parser.feed('<!DOCTYPE doc [\n')
+ parser.feed(' <!ENTITY test SYSTEM "whatever">\n')
+ parser.feed(']>\n')
+ parser.feed('<doc>&test;</doc>')
+ parser.close()
+
+ return result.getvalue() == start + "<doc><entity></entity></doc>"
+
# ===== Attributes support
class AttrGatherer(ContentHandler):
@@ -440,5 +460,3 @@ for (name, value) in items:
print "%d tests, %d failures" % (tests, fails)
if fails != 0:
raise TestFailed, "%d of %d tests failed" % (fails, tests)
-
-make_test_output()