from xml.etree import ElementTree as ET try: from StringIO import StringIO except ImportError: # python3000 from io import StringIO import unittest class TestElementTree(unittest.TestCase): def test_cross_boundary(self): text = 'This is a very long string that will cross the page bounderies of 8K' buf = ['', ''] for _ in range(214): # this number depends on the chunk size in iterparse.next buf.append(' ' + text + '') buf.append('') for event, elem in ET.iterparse(StringIO('\n'.join(buf)), events=('start',)): if elem.tag == 'b': self.assertEqual(elem.text, text) if __name__ == '__main__': unittest.main()