[Python-checkins] r85528 - in python/branches/py3k/Lib: test/test_pyexpat.py xml/parsers/expat.py

georg.brandl python-checkins at python.org
Fri Oct 15 17:25:23 CEST 2010


Author: georg.brandl
Date: Fri Oct 15 17:25:23 2010
New Revision: 85528
Log:
#5355 followup: add unit test for new dictionaries, and provide submodules from xml.parsers.expat as advertised.
Modified:
 python/branches/py3k/Lib/test/test_pyexpat.py
 python/branches/py3k/Lib/xml/parsers/expat.py
Modified: python/branches/py3k/Lib/test/test_pyexpat.py
==============================================================================
--- python/branches/py3k/Lib/test/test_pyexpat.py	(original)
+++ python/branches/py3k/Lib/test/test_pyexpat.py	Fri Oct 15 17:25:23 2010
@@ -2,10 +2,10 @@
 # handler, are obscure and unhelpful.
 
 from io import BytesIO
-import sys
 import unittest
 
 from xml.parsers import expat
+from xml.parsers.expat import errors
 
 from test.support import sortdict, run_unittest
 
@@ -575,7 +575,7 @@
 parser.Parse(xml2, 1)
 self.assertEquals(self.n, 4)
 
-class MalformedInputText(unittest.TestCase):
+class MalformedInputTest(unittest.TestCase):
 def test1(self):
 xml = "0円\r\n"
 parser = expat.ParserCreate()
@@ -594,6 +594,23 @@
 except expat.ExpatError as e:
 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():
 run_unittest(SetAttributeTest,
 ParseTest,
@@ -604,7 +621,8 @@
 PositionTest,
 sf1296433Test,
 ChardataBufferTest,
- MalformedInputText)
+ MalformedInputTest,
+ ErrorMessageTest)
 
 if __name__ == "__main__":
 test_main()
Modified: python/branches/py3k/Lib/xml/parsers/expat.py
==============================================================================
--- python/branches/py3k/Lib/xml/parsers/expat.py	(original)
+++ python/branches/py3k/Lib/xml/parsers/expat.py	Fri Oct 15 17:25:23 2010
@@ -1,4 +1,10 @@
 """Interface to the Expat non-validating XML parser."""
 __version__ = '$Revision$'
 
+import sys
+
 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


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /