diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
index 98cc58e9ce8627..05f66fdca129a4 100644
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -493,6 +493,21 @@ def func(out):
func(result)
self.assertFalse(result.closed)
+ def test_xmlgen_fragment(self):
+ result = self.ioclass()
+ gen = XMLGenerator(result)
+
+ # Don't call gen.startDocument()
+ gen.startElement("foo", {"a": "1.0"})
+ gen.characters("Hello")
+ gen.endElement("foo")
+ gen.startElement("bar", {"b": "2.0"})
+ gen.endElement("bar")
+ # Don't call gen.endDocument()
+
+ self.assertEqual(result.getvalue(),
+ self.xml('Hello')[len(self.xml('')):])
+
class StringXmlgenTest(XmlgenTest, unittest.TestCase):
ioclass = StringIO