Skip to content

Commit

Permalink
sax: Test method xml.sax.expatreader.ExpatParser.flush
Browse files Browse the repository at this point in the history
  • Loading branch information
hartwork committed Feb 18, 2024
1 parent 8ecc336 commit e94e420
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Lib/test/test_sax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1214,6 +1215,30 @@ def test_expat_incremental_reset(self):

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

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("<doc ")
parser.feed(">")

if pyexpat.version_info >= (2, 6, 0):
self.assertEqual(result.getvalue(), start)
else:
self.assertEqual(result.getvalue(), start + b"<doc>")

parser.flush() # no-op for Expat <2.6.0

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

parser.feed("</doc>")
parser.close()

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

# ===== Locator support

def test_expat_locator_noinfo(self):
Expand Down

0 comments on commit e94e420

Please sign in to comment.