From 8b3441fd4dd3f447c9e45024b41e403e7a599446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Thu, 16 Jun 2022 13:12:40 +0200 Subject: [PATCH 1/2] gh-93018: Fix for the compatibility problems with expat This is another take on #93022, fixes #93018. 1. I believe it is inappropriate to assert on the error message for the external API. Error messages are not part of the provided contract with its users. 2. I don't think we are really care what exact exception is thrown, it is much more important that non-well-formed XML is discovered. 3. Changing tests based on the version of library seems as a code smell to me, but that's personal opinion. --- Lib/test/test_minidom.py | 24 +++++++------------ ...2-06-16-13-26-31.gh-issue-93018.wvNx76.rst | 1 + 2 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 97620258d82f6b..9c3d955cf41942 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -1149,14 +1149,10 @@ def testEncodings(self): # Verify that character decoding errors raise exceptions instead # of crashing - if pyexpat.version_info >= (2, 4, 5): - self.assertRaises(ExpatError, parseString, - b'') - self.assertRaises(ExpatError, parseString, - b'Comment \xe7a va ? Tr\xe8s bien ?') - else: - self.assertRaises(UnicodeDecodeError, parseString, - b'Comment \xe7a va ? Tr\xe8s bien ?') + with self.assertRaises((UnicodeDecodeError, ExpatError)): + parseString( + b'Comment \xe7a va ? Tr\xe8s bien ?' + ) doc.unlink() @@ -1617,13 +1613,11 @@ def testEmptyXMLNSValue(self): self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE) def testExceptionOnSpacesInXMLNSValue(self): - if pyexpat.version_info >= (2, 4, 5): - context = self.assertRaisesRegex(ExpatError, 'syntax error') - else: - context = self.assertRaisesRegex(ValueError, 'Unsupported syntax') - - with context: - parseString('') + with self.assertRaises((ValueError, ExpatError)): + parseString( + '' + + '' + ) def testDocRemoveChild(self): doc = parse(tstfile) diff --git a/Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst b/Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst new file mode 100644 index 00000000000000..42e1dab28b5517 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst @@ -0,0 +1 @@ +Fix for the compatibility problems with expat made more robust. From f9790568477d0124f4a27dc4f7648c6901d230db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Fri, 12 Aug 2022 20:17:07 +0200 Subject: [PATCH 2/2] Better NEWS message. --- .../next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst b/Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst index 42e1dab28b5517..a8fb98048e4023 100644 --- a/Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst +++ b/Misc/NEWS.d/next/Tests/2022-06-16-13-26-31.gh-issue-93018.wvNx76.rst @@ -1 +1 @@ -Fix for the compatibility problems with expat made more robust. +Make two tests forgiving towards host system libexpat with backported security fixes applied.