diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index eda4e6a46df437a..92443907924bcc2 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -19,6 +19,7 @@ from io import BytesIO, StringIO import codecs import os.path +import pyexpat import shutil import sys from urllib.error import URLError @@ -1214,6 +1215,30 @@ def test_expat_incremental_reset(self): self.assertEqual(result.getvalue(), start + b"text") + def test_expat_incremental_reparse_deferral(self): + result = BytesIO() + xmlgen = XMLGenerator(result) + parser = create_parser() + parser.setContentHandler(xmlgen) + + # This artificial chunking triggers reparse deferral with Expat >=2.6.0 + parser.feed("") + + if pyexpat.version_info >= (2, 6, 0): + self.assertEqual(result.getvalue(), start) + else: + self.assertEqual(result.getvalue(), start + b"") + + parser.flush() # no-op for Expat <2.6.0 + + self.assertEqual(result.getvalue(), start + b"") + + parser.feed("") + parser.close() + + self.assertEqual(result.getvalue(), start + b"") + # ===== Locator support def test_expat_locator_noinfo(self):