Commit 91d2a3fb authored by Georg Brandl's avatar Georg Brandl

#5355 followup: add unit test for new dictionaries, and provide submodules...

#5355 followup: add unit test for new dictionaries, and provide submodules from xml.parsers.expat as advertised.
parent 279b56d9
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
# handler, are obscure and unhelpful. # handler, are obscure and unhelpful.
from io import BytesIO from io import BytesIO
import sys
import unittest import unittest
from xml.parsers import expat from xml.parsers import expat
from xml.parsers.expat import errors
from test.support import sortdict, run_unittest from test.support import sortdict, run_unittest
...@@ -575,7 +575,7 @@ class ChardataBufferTest(unittest.TestCase): ...@@ -575,7 +575,7 @@ class ChardataBufferTest(unittest.TestCase):
parser.Parse(xml2, 1) parser.Parse(xml2, 1)
self.assertEquals(self.n, 4) self.assertEquals(self.n, 4)
class MalformedInputText(unittest.TestCase): class MalformedInputTest(unittest.TestCase):
def test1(self): def test1(self):
xml = "\0\r\n" xml = "\0\r\n"
parser = expat.ParserCreate() parser = expat.ParserCreate()
...@@ -594,6 +594,23 @@ class MalformedInputText(unittest.TestCase): ...@@ -594,6 +594,23 @@ class MalformedInputText(unittest.TestCase):
except expat.ExpatError as e: except expat.ExpatError as e:
self.assertEquals(str(e), 'XML declaration not well-formed: line 1, column 14') self.assertEquals(str(e), 'XML declaration not well-formed: line 1, column 14')
class ErrorMessageTest(unittest.TestCase):
def test_codes(self):
# verify mapping of errors.codes and errors.messages
self.assertEqual(errors.XML_ERROR_SYNTAX,
errors.messages[errors.codes[errors.XML_ERROR_SYNTAX]])
def test_expaterror(self):
xml = '<'
parser = expat.ParserCreate()
try:
parser.Parse(xml, True)
self.fail()
except expat.ExpatError as e:
self.assertEquals(e.code,
errors.codes[errors.XML_ERROR_UNCLOSED_TOKEN])
def test_main(): def test_main():
run_unittest(SetAttributeTest, run_unittest(SetAttributeTest,
ParseTest, ParseTest,
...@@ -604,7 +621,8 @@ def test_main(): ...@@ -604,7 +621,8 @@ def test_main():
PositionTest, PositionTest,
sf1296433Test, sf1296433Test,
ChardataBufferTest, ChardataBufferTest,
MalformedInputText) MalformedInputTest,
ErrorMessageTest)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
"""Interface to the Expat non-validating XML parser.""" """Interface to the Expat non-validating XML parser."""
__version__ = '$Revision$' __version__ = '$Revision$'
import sys
from pyexpat import * from pyexpat import *
# provide pyexpat submodules as xml.parsers.expat submodules
sys.modules['xml.parsers.expat.model'] = model
sys.modules['xml.parsers.expat.errors'] = errors
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment