diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2000-09-24 20:19:45 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2000-09-24 20:19:45 (GMT) |
commit | e292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b (patch) | |
tree | 1b194ae63bc189cba2f8473de3a14059b614e273 /Lib/test | |
parent | bc1c1c98eb360e549663b1440a9c4f3d99d1d919 (diff) | |
download | cpython-e292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b.zip cpython-e292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b.tar.gz cpython-e292a24589c4eb31c2b0a0cc45f58c3abd0ffc1b.tar.bz2 |
Added EntityResolver and DTDHandler (patch 101631) with test cases.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/output/test_sax | 4 | ||||
-rw-r--r-- | Lib/test/test_sax.py | 50 |
2 files changed, 37 insertions, 17 deletions
diff --git a/Lib/test/output/test_sax b/Lib/test/output/test_sax index 19aa71c..53c5f97 100644 --- a/Lib/test/output/test_sax +++ b/Lib/test/output/test_sax @@ -6,6 +6,8 @@ Passed test_escape_basic Passed test_escape_extra Passed test_expat_attrs_empty Passed test_expat_attrs_wattr +Passed test_expat_dtdhandler +Passed test_expat_entityresolver Passed test_expat_inpsource_filename Passed test_expat_inpsource_stream Passed test_expat_inpsource_sysid @@ -20,4 +22,4 @@ Passed test_xmlgen_content_escape Passed test_xmlgen_ignorable Passed test_xmlgen_ns Passed test_xmlgen_pi -21 tests, 0 failures +23 tests, 0 failures 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() |