Skip to content

Commit aa7523f

Browse files
committed
test_minidom.py: Support Expat >=2.4.5
1 parent dd7da01 commit aa7523f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Lib/test/test_minidom.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from test import support
77
import unittest
88

9+
import pyexpat
910
import xml.dom.minidom
1011

1112
from xml.dom.minidom import parse, Node, Document, parseString
1213
from xml.dom.minidom import getDOMImplementation
14+
from xml.parsers.expat import ExpatError
1315

1416

1517
tstfile = support.findfile("test.xml", subdir="xmltestdata")
@@ -1147,7 +1149,13 @@ def testEncodings(self):
11471149

11481150
# Verify that character decoding errors raise exceptions instead
11491151
# 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,
11511159
b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
11521160

11531161
doc.unlink()
@@ -1609,7 +1617,12 @@ def testEmptyXMLNSValue(self):
16091617
self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE)
16101618

16111619
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:
16131626
parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
16141627

16151628
def testDocRemoveChild(self):

0 commit comments

Comments
 (0)