|
6 | 6 | from test import support
|
7 | 7 | import unittest
|
8 | 8 |
|
| 9 | +import pyexpat |
9 | 10 | import xml.dom.minidom
|
10 | 11 |
|
11 | 12 | from xml.dom.minidom import parse, Node, Document, parseString
|
12 | 13 | from xml.dom.minidom import getDOMImplementation
|
| 14 | +from xml.parsers.expat import ExpatError |
13 | 15 |
|
14 | 16 |
|
15 | 17 | tstfile = support.findfile("test.xml", subdir="xmltestdata")
|
@@ -1147,7 +1149,13 @@ def testEncodings(self):
|
1147 | 1149 |
|
1148 | 1150 | # Verify that character decoding errors raise exceptions instead
|
1149 | 1151 | # of crashing
|
1150 |
| - self.assertRaises(UnicodeDecodeError, parseString, |
| 1152 | + if pyexpat.version_info >= (2, 4, 5): |
| 1153 | + self.assertRaises(ExpatError, parseString, |
| 1154 | + b'<fran\xe7ais></fran\xe7ais>') |
| 1155 | + self.assertRaises(ExpatError, parseString, |
| 1156 | + b'<franais>Comment \xe7a va ? Tr\xe8s bien ?</franais>') |
| 1157 | + else: |
| 1158 | + self.assertRaises(UnicodeDecodeError, parseString, |
1151 | 1159 | b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
|
1152 | 1160 |
|
1153 | 1161 | doc.unlink()
|
@@ -1609,7 +1617,12 @@ def testEmptyXMLNSValue(self):
|
1609 | 1617 | self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
|
1610 | 1618 |
|
1611 | 1619 | def testExceptionOnSpacesInXMLNSValue(self):
|
1612 |
| - with self.assertRaisesRegex(ValueError, 'Unsupported syntax'): |
| 1620 | + if pyexpat.version_info >= (2, 4, 5): |
| 1621 | + context = self.assertRaisesRegex(ExpatError, 'syntax error') |
| 1622 | + else: |
| 1623 | + context = self.assertRaisesRegex(ValueError, 'Unsupported syntax') |
| 1624 | + |
| 1625 | + with context: |
1613 | 1626 | parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
|
1614 | 1627 |
|
1615 | 1628 | def testDocRemoveChild(self):
|
|
0 commit comments