2024-04-30 17:37:14 +02:00
|
|
|
|
---
|
2024-05-01 11:01:36 +02:00
|
|
|
|
Lib/test/support/__init__.py | 16 ++++++++++++++--
|
|
|
|
|
Lib/test/test_minidom.py | 23 +++++++++--------------
|
2024-05-02 01:30:08 +02:00
|
|
|
|
Lib/test/test_pyexpat.py | 12 +++++-------
|
2024-04-30 17:37:14 +02:00
|
|
|
|
Lib/test/test_sax.py | 18 +++++++++---------
|
2024-05-01 11:01:36 +02:00
|
|
|
|
Lib/test/test_xml_etree.py | 12 ------------
|
2024-05-02 01:30:08 +02:00
|
|
|
|
5 files changed, 37 insertions(+), 44 deletions(-)
|
2024-04-30 17:37:14 +02:00
|
|
|
|
|
|
|
|
|
--- a/Lib/test/support/__init__.py
|
|
|
|
|
+++ b/Lib/test/support/__init__.py
|
|
|
|
|
@@ -8,6 +8,7 @@ import dataclasses
|
|
|
|
|
import functools
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
+import pyexpat
|
|
|
|
|
import stat
|
|
|
|
|
import sys
|
|
|
|
|
import sysconfig
|
|
|
|
|
@@ -56,7 +57,7 @@ __all__ = [
|
|
|
|
|
"run_with_tz", "PGO", "missing_compiler_executable",
|
|
|
|
|
"ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST",
|
|
|
|
|
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
|
|
|
|
|
- "skip_on_s390x",
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+ "skip_on_s390x", "fails_with_expat_2_6_0", "is_expat_2_6_0"
|
2024-04-30 17:37:14 +02:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2024-05-01 11:01:36 +02:00
|
|
|
|
@@ -2240,6 +2241,17 @@ def copy_python_src_ignore(path, names):
|
|
|
|
|
}
|
|
|
|
|
return ignored
|
|
|
|
|
|
|
|
|
|
-#Windows doesn't have os.uname() but it doesn't support s390x.
|
|
|
|
|
+
|
|
|
|
|
+# Windows doesn't have os.uname() but it doesn't support s390x.
|
2024-04-30 17:37:14 +02:00
|
|
|
|
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
|
|
|
|
|
'skipped on s390x')
|
|
|
|
|
+
|
|
|
|
|
+
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+@functools.lru_cache
|
|
|
|
|
+def _is_expat_2_6_0():
|
2024-05-02 01:30:08 +02:00
|
|
|
|
+ return hasattr(pyexpat.ParserCreate(), 'SetReparseDeferralEnabled')
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+is_expat_2_6_0 = _is_expat_2_6_0()
|
|
|
|
|
+
|
2024-04-30 17:37:14 +02:00
|
|
|
|
+fails_with_expat_2_6_0 = (unittest.expectedFailure
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+ if is_expat_2_6_0
|
|
|
|
|
+ else lambda test: test)
|
|
|
|
|
--- a/Lib/test/test_minidom.py
|
|
|
|
|
+++ b/Lib/test/test_minidom.py
|
|
|
|
|
@@ -6,7 +6,6 @@ import io
|
|
|
|
|
from test import support
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
-import pyexpat
|
|
|
|
|
import xml.dom.minidom
|
|
|
|
|
|
|
|
|
|
from xml.dom.minidom import parse, Attr, Node, Document, parseString
|
|
|
|
|
@@ -1163,13 +1162,11 @@ class MinidomTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
# Verify that character decoding errors raise exceptions instead
|
|
|
|
|
# of crashing
|
|
|
|
|
- if pyexpat.version_info >= (2, 4, 5):
|
|
|
|
|
- self.assertRaises(ExpatError, parseString,
|
|
|
|
|
- b'<fran\xe7ais></fran\xe7ais>')
|
|
|
|
|
- self.assertRaises(ExpatError, parseString,
|
|
|
|
|
- b'<franais>Comment \xe7a va ? Tr\xe8s bien ?</franais>')
|
|
|
|
|
- else:
|
|
|
|
|
- self.assertRaises(UnicodeDecodeError, parseString,
|
|
|
|
|
+ # It doesn’t make any sense to insist on the exact text of the
|
|
|
|
|
+ # error message, or even the exact Exception … it is enough that
|
|
|
|
|
+ # the error has been discovered.
|
|
|
|
|
+ with self.assertRaises((UnicodeDecodeError, ExpatError)):
|
|
|
|
|
+ parseString(
|
|
|
|
|
b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
|
|
|
|
|
|
|
|
|
|
doc.unlink()
|
|
|
|
|
@@ -1631,12 +1628,10 @@ class MinidomTest(unittest.TestCase):
|
|
|
|
|
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:
|
|
|
|
|
+ # It doesn’t make any sense to insist on the exact text of the
|
|
|
|
|
+ # error message, or even the exact Exception … it is enough that
|
|
|
|
|
+ # the error has been discovered.
|
|
|
|
|
+ with self.assertRaises((ExpatError, ValueError)):
|
|
|
|
|
parseString('<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>')
|
|
|
|
|
|
|
|
|
|
def testDocRemoveChild(self):
|
2024-04-30 17:37:14 +02:00
|
|
|
|
--- a/Lib/test/test_pyexpat.py
|
|
|
|
|
+++ b/Lib/test/test_pyexpat.py
|
|
|
|
|
@@ -14,8 +14,7 @@ from test.support import os_helper
|
|
|
|
|
from xml.parsers import expat
|
|
|
|
|
from xml.parsers.expat import errors
|
|
|
|
|
|
|
|
|
|
-from test.support import sortdict, is_emscripten, is_wasi
|
|
|
|
|
-
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+from test.support import sortdict, is_emscripten, is_wasi, is_expat_2_6_0
|
2024-04-30 17:37:14 +02:00
|
|
|
|
|
|
|
|
|
class SetAttributeTest(unittest.TestCase):
|
|
|
|
|
def setUp(self):
|
2024-05-01 11:01:36 +02:00
|
|
|
|
@@ -770,9 +769,8 @@ class ReparseDeferralTest(unittest.TestC
|
|
|
|
|
self.assertIs(parser.GetReparseDeferralEnabled(), enabled)
|
2024-04-30 17:37:14 +02:00
|
|
|
|
|
2024-05-01 11:01:36 +02:00
|
|
|
|
def test_reparse_deferral_enabled(self):
|
|
|
|
|
- if expat.version_info < (2, 6, 0):
|
|
|
|
|
- self.skipTest(f'Expat {expat.version_info} does not '
|
|
|
|
|
- 'support reparse deferral')
|
|
|
|
|
+ if not is_expat_2_6_0:
|
|
|
|
|
+ self.skipTest("Linked libexpat doesn't support reparse deferral")
|
2024-04-30 17:37:14 +02:00
|
|
|
|
|
|
|
|
|
started = []
|
|
|
|
|
|
2024-05-02 01:30:08 +02:00
|
|
|
|
@@ -801,9 +799,9 @@ class ReparseDeferralTest(unittest.TestC
|
2024-04-30 17:37:14 +02:00
|
|
|
|
|
|
|
|
|
parser = expat.ParserCreate()
|
|
|
|
|
parser.StartElementHandler = start_element
|
|
|
|
|
- if expat.version_info >= (2, 6, 0):
|
2024-05-02 01:30:08 +02:00
|
|
|
|
+ if is_expat_2_6_0:
|
|
|
|
|
parser.SetReparseDeferralEnabled(False)
|
|
|
|
|
- self.assertFalse(parser.GetReparseDeferralEnabled())
|
|
|
|
|
+ self.assertFalse(parser.GetReparseDeferralEnabled())
|
2024-04-30 17:37:14 +02:00
|
|
|
|
|
|
|
|
|
for chunk in (b'<doc', b'/>'):
|
2024-05-02 01:30:08 +02:00
|
|
|
|
parser.Parse(chunk, False)
|
2024-04-30 17:37:14 +02:00
|
|
|
|
--- a/Lib/test/test_sax.py
|
|
|
|
|
+++ b/Lib/test/test_sax.py
|
|
|
|
|
@@ -19,13 +19,11 @@ from xml.sax.xmlreader import InputSourc
|
|
|
|
|
from io import BytesIO, StringIO
|
|
|
|
|
import codecs
|
|
|
|
|
import os.path
|
|
|
|
|
-import pyexpat
|
|
|
|
|
import shutil
|
|
|
|
|
import sys
|
|
|
|
|
from urllib.error import URLError
|
|
|
|
|
import urllib.request
|
|
|
|
|
-from test.support import os_helper
|
|
|
|
|
-from test.support import findfile
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+from test.support import os_helper, findfile, is_expat_2_6_0
|
2024-04-30 17:37:14 +02:00
|
|
|
|
from test.support.os_helper import FakePath, TESTFN
|
|
|
|
|
|
|
|
|
|
|
2024-05-01 11:01:36 +02:00
|
|
|
|
@@ -1215,10 +1213,10 @@ class ExpatReaderTest(XmlTestBase):
|
2024-04-30 17:37:14 +02:00
|
|
|
|
|
|
|
|
|
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):
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+ if not is_expat_2_6_0:
|
|
|
|
|
+ self.skipTest("Linked libexpat doesn't support reparse deferral")
|
|
|
|
|
+
|
2024-04-30 17:37:14 +02:00
|
|
|
|
result = BytesIO()
|
|
|
|
|
xmlgen = XMLGenerator(result)
|
2024-05-01 11:01:36 +02:00
|
|
|
|
parser = create_parser()
|
|
|
|
|
@@ -1241,6 +1239,9 @@ class ExpatReaderTest(XmlTestBase):
|
2024-04-30 17:37:14 +02:00
|
|
|
|
self.assertEqual(result.getvalue(), start + b"<doc></doc>")
|
|
|
|
|
|
|
|
|
|
def test_flush_reparse_deferral_disabled(self):
|
2024-05-01 11:01:36 +02:00
|
|
|
|
+ if not is_expat_2_6_0:
|
|
|
|
|
+ self.skipTest("Linked libexpat doesn't support reparse deferral")
|
|
|
|
|
+
|
2024-04-30 17:37:14 +02:00
|
|
|
|
result = BytesIO()
|
|
|
|
|
xmlgen = XMLGenerator(result)
|
2024-05-01 11:01:36 +02:00
|
|
|
|
parser = create_parser()
|
|
|
|
|
@@ -1249,9 +1250,8 @@ class ExpatReaderTest(XmlTestBase):
|
2024-04-30 17:37:14 +02:00
|
|
|
|
for chunk in ("<doc", ">"):
|
|
|
|
|
parser.feed(chunk)
|
|
|
|
|
|
|
|
|
|
- if pyexpat.version_info >= (2, 6, 0):
|
|
|
|
|
- parser._parser.SetReparseDeferralEnabled(False)
|
|
|
|
|
- self.assertEqual(result.getvalue(), start) # i.e. no elements started
|
|
|
|
|
+ parser._parser.SetReparseDeferralEnabled(False)
|
|
|
|
|
+ self.assertEqual(result.getvalue(), start) # i.e. no elements started
|
|
|
|
|
|
|
|
|
|
self.assertFalse(parser._parser.GetReparseDeferralEnabled())
|
|
|
|
|
|
|
|
|
|
--- a/Lib/test/test_xml_etree.py
|
|
|
|
|
+++ b/Lib/test/test_xml_etree.py
|
|
|
|
|
@@ -13,7 +13,6 @@ import itertools
|
|
|
|
|
import operator
|
|
|
|
|
import os
|
|
|
|
|
import pickle
|
|
|
|
|
-import pyexpat
|
|
|
|
|
import sys
|
|
|
|
|
import textwrap
|
|
|
|
|
import types
|
2024-05-01 11:01:36 +02:00
|
|
|
|
@@ -1424,12 +1423,6 @@ class XMLPullParserTest(unittest.TestCas
|
2024-04-20 00:20:05 +02:00
|
|
|
|
self.assert_event_tags(parser, [('end', 'root')])
|
|
|
|
|
self.assertIsNone(parser.close())
|
|
|
|
|
|
2024-05-01 11:01:36 +02:00
|
|
|
|
- def test_simple_xml_chunk_1(self):
|
|
|
|
|
- self.test_simple_xml(chunk_size=1, flush=True)
|
|
|
|
|
-
|
|
|
|
|
- def test_simple_xml_chunk_5(self):
|
|
|
|
|
- self.test_simple_xml(chunk_size=5, flush=True)
|
|
|
|
|
-
|
|
|
|
|
def test_simple_xml_chunk_22(self):
|
|
|
|
|
self.test_simple_xml(chunk_size=22)
|
2024-04-20 00:20:05 +02:00
|
|
|
|
|
2024-05-01 11:01:36 +02:00
|
|
|
|
@@ -1627,9 +1620,6 @@ class XMLPullParserTest(unittest.TestCas
|
2024-04-30 17:37:14 +02:00
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
ET.XMLPullParser(events=('start', 'end', 'bogus'))
|
2024-04-20 00:20:05 +02:00
|
|
|
|
|
2024-04-30 17:37:14 +02:00
|
|
|
|
- @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):
|
2024-04-20 00:20:05 +02:00
|
|
|
|
parser = ET.XMLPullParser(events=('start', 'end'))
|
|
|
|
|
|
2024-05-01 11:01:36 +02:00
|
|
|
|
@@ -1656,8 +1646,6 @@ class XMLPullParserTest(unittest.TestCas
|
2024-04-20 00:20:05 +02:00
|
|
|
|
|
2024-04-30 17:37:14 +02:00
|
|
|
|
for chunk in ("<doc", ">"):
|
|
|
|
|
parser.feed(chunk)
|
|
|
|
|
-
|
|
|
|
|
- if pyexpat.version_info >= (2, 6, 0):
|
|
|
|
|
if not ET is pyET:
|
|
|
|
|
self.skipTest(f'XMLParser.(Get|Set)ReparseDeferralEnabled '
|
|
|
|
|
'methods not available in C')
|