|
9 | 9 |
|
10 | 10 | from xml.dom.minidom import parse, Node, Document, parseString
|
11 | 11 | from xml.dom.minidom import getDOMImplementation
|
| 12 | +from xml.parsers.expat import ExpatError |
12 | 13 |
|
13 | 14 |
|
14 | 15 | tstfile = support.findfile("test.xml", subdir="xmltestdata")
|
@@ -1156,8 +1157,12 @@ def testEncodings(self):
|
1156 | 1157 |
|
1157 | 1158 | # Verify that character decoding errors raise exceptions instead
|
1158 | 1159 | # of crashing
|
1159 |
| - self.assertRaises(UnicodeDecodeError, parseString, |
1160 |
| - b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>') |
| 1160 | + # It doesn’t make any sense to insist on the exact text of the |
| 1161 | + # error message, or even the exact Exception … it is enough that |
| 1162 | + # the error has been discovered. |
| 1163 | + with self.assertRaises((UnicodeDecodeError, ExpatError)): |
| 1164 | + parseString( |
| 1165 | + b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>') |
1161 | 1166 |
|
1162 | 1167 | doc.unlink()
|
1163 | 1168 |
|
@@ -1602,8 +1607,11 @@ def testEmptyXMLNSValue(self):
|
1602 | 1607 | self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
|
1603 | 1608 |
|
1604 | 1609 | def testExceptionOnSpacesInXMLNSValue(self):
|
1605 |
| - with self.assertRaisesRegex(ValueError, 'Unsupported syntax'): |
1606 |
| - parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>') |
| 1610 | + # It doesn’t make any sense to insist on the exact text of the |
| 1611 | + # error message, or even the exact Exception … it is enough that |
| 1612 | + # the error has been discovered. |
| 1613 | + with self.assertRaises((ExpatError, ValueError)): |
| 1614 | + parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>') |
1607 | 1615 |
|
1608 | 1616 | def testDocRemoveChild(self):
|
1609 | 1617 | doc = parse(tstfile)
|
|
0 commit comments