8000 [3.11] gh-117187: Fix XML tests for vanilla Expat <2.6.0 (GH-117203) by miss-islington · Pull Request #117245 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.11] gh-117187: Fix XML tests for vanilla Expat <2.6.0 (GH-117203) #117245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
gh-117187: Fix XML tests for vanilla Expat <2.6.0 (GH-117203)
This fixes XML unittest fallout from the #115398 security fix.  When configured using `--with-system-expat` on systems with older pre 2.6.0 versions of libexpat, our unittests were failing.

* sax|etree: Simplify Expat version guard where simplifiab
8000
le

Idea by Matěj Cepl

* sax|etree: Fix reparse deferral tests for vanilla Expat <2.6.0

This *does not fix* the case of distros with an older version of libexpat with the 2.6.0 feature backported as a security fix.  (Ubuntu is a known example of this with its libexpat1 2.5.0-2ubunutu0.1 package)
(cherry picked from commit 9f74e86)

Co-authored-by: Sebastian Pipping <sebastian@pipping.org>
  • Loading branch information
hartwork authored and miss-islington committed Mar 26, 2024
commit 364e17ae5fc3e737a63cbd908d68e1bbbc7c12e2
8 changes: 4 additions & 4 deletions Lib/test/test_sax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,10 +1215,10 @@ def test_expat_incremental_reset(self):

self.assertEqual(result.getvalue(), start + b"<doc>text</doc>")

@unittest.skipIf(pyexpat.version_info < (2, 6, 0),
f'Expat {pyexpat.version_info} does not '
'support reparse deferral')
def test_flush_reparse_deferral_enabled(self):
if pyexpat.version_info < (2, 6, 0):
self.skipTest(f'Expat {pyexpat.version_info} does not support reparse deferral')

result = BytesIO()
xmlgen = XMLGenerator(result)
parser = create_parser()
Expand Down Expand Up @@ -1251,8 +1251,8 @@ def test_flush_reparse_deferral_disabled(self):

if pyexpat.version_info >= (2, 6, 0):
parser._parser.SetReparseDeferralEnabled(False)
self.assertEqual(result.getvalue(), start) # i.e. no elements started

self.assertEqual(result.getvalue(), start) # i.e. no elements started
self.assertFalse(parser._parser.GetReparseDeferralEnabled())

parser.flush()
Expand Down
9 changes: 4 additions & 5 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1627,11 +1627,10 @@ def test_unknown_event(self):
with self.assertRaises(ValueError):
ET.XMLPullParser(events=('start', 'end', 'bogus'))

@unittest.skipIf(pyexpat.version_info < (2, 6, 0),
f'Expat {pyexpat.version_info} does not '
'support reparse deferral')
def test_flush_reparse_deferral_enabled(self):
if pyexpat.version_info < (2, 6, 0):
self.skipTest(f'Expat {pyexpat.version_info} does not '
'support reparse deferral')

parser = ET.XMLPullParser(events=('start', 'end'))

for chunk in ("<doc", ">"):
Expand Down Expand Up @@ -1663,8 +1662,8 @@ def test_flush_reparse_deferral_disabled(self):
self.skipTest(f'XMLParser.(Get|Set)ReparseDeferralEnabled '
'methods not available in C')
parser._parser._parser.SetReparseDeferralEnabled(False)
self.assert_event_tags(parser, []) # i.e. no elements started

self.assert_event_tags(parser, []) # i.e. no elements started
if ET is pyET:
self.assertFalse(parser._parser._parser.GetReparseDeferralEnabled())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix XML tests for vanilla Expat <2.6.0.
0