diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-10-17 22:46:45 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-10-17 22:46:45 (GMT) |
commit | a90032a3fb526916a95595a7f3f570dadf9d9380 (patch) | |
tree | 3e90ad3a775b938b581e7eb49075dc552da22b02 /Lib/test/test_sax.py | |
parent | 961aaf5cfa2f5585ab72f940d3329d9f425cbe34 (diff) | |
download | cpython-a90032a3fb526916a95595a7f3f570dadf9d9380.zip cpython-a90032a3fb526916a95595a7f3f570dadf9d9380.tar.gz cpython-a90032a3fb526916a95595a7f3f570dadf9d9380.tar.bz2 |
#1343: Add short_empty_elements option to XMLGenerator.
Patch and tests by Neil Muller.
Diffstat (limited to 'Lib/test/test_sax.py')
-rw-r--r-- | Lib/test/test_sax.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 911e763..143ddf2 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -170,6 +170,16 @@ class XmlgenTest(unittest.TestCase): self.assertEquals(result.getvalue(), start + "<doc></doc>") + def test_xmlgen_basic_empty(self): + result = StringIO() + gen = XMLGenerator(result, short_empty_elements=True) + gen.startDocument() + gen.startElement("doc", {}) + gen.endElement("doc") + gen.endDocument() + + self.assertEquals(result.getvalue(), start + "<doc/>") + def test_xmlgen_content(self): result = StringIO() gen = XMLGenerator(result) @@ -182,6 +192,18 @@ class XmlgenTest(unittest.TestCase): self.assertEquals(result.getvalue(), start + "<doc>huhei</doc>") + def test_xmlgen_content_empty(self): + result = StringIO() + gen = XMLGenerator(result, short_empty_elements=True) + + gen.startDocument() + gen.startElement("doc", {}) + gen.characters("huhei") + gen.endElement("doc") + gen.endDocument() + + self.assertEquals(result.getvalue(), start + "<doc>huhei</doc>") + def test_xmlgen_pi(self): result = StringIO() gen = XMLGenerator(result) @@ -239,6 +261,18 @@ class XmlgenTest(unittest.TestCase): self.assertEquals(result.getvalue(), start + "<doc> </doc>") + def test_xmlgen_ignorable_empty(self): + result = StringIO() + gen = XMLGenerator(result, short_empty_elements=True) + + gen.startDocument() + gen.startElement("doc", {}) + gen.ignorableWhitespace(" ") + gen.endElement("doc") + gen.endDocument() + + self.assertEquals(result.getvalue(), start + "<doc> </doc>") + def test_xmlgen_ns(self): result = StringIO() gen = XMLGenerator(result) @@ -257,6 +291,24 @@ class XmlgenTest(unittest.TestCase): ('<ns1:doc xmlns:ns1="%s"><udoc></udoc></ns1:doc>' % ns_uri)) + def test_xmlgen_ns_empty(self): + result = StringIO() + gen = XMLGenerator(result, short_empty_elements=True) + + gen.startDocument() + gen.startPrefixMapping("ns1", ns_uri) + gen.startElementNS((ns_uri, "doc"), "ns1:doc", {}) + # add an unqualified name + gen.startElementNS((None, "udoc"), None, {}) + gen.endElementNS((None, "udoc"), None) + gen.endElementNS((ns_uri, "doc"), "ns1:doc") + gen.endPrefixMapping("ns1") + gen.endDocument() + + self.assertEquals(result.getvalue(), start + \ + ('<ns1:doc xmlns:ns1="%s"><udoc/></ns1:doc>' % + ns_uri)) + def test_1463026_1(self): result = StringIO() gen = XMLGenerator(result) @@ -268,6 +320,17 @@ class XmlgenTest(unittest.TestCase): self.assertEquals(result.getvalue(), start+'<a b="c"></a>') + def test_1463026_1_empty(self): + result = StringIO() + gen = XMLGenerator(result, short_empty_elements=True) + + gen.startDocument() + gen.startElementNS((None, 'a'), 'a', {(None, 'b'):'c'}) + gen.endElementNS((None, 'a'), 'a') + gen.endDocument() + + self.assertEquals(result.getvalue(), start+'<a b="c"/>') + def test_1463026_2(self): result = StringIO() gen = XMLGenerator(result) @@ -281,6 +344,19 @@ class XmlgenTest(unittest.TestCase): self.assertEquals(result.getvalue(), start+'<a xmlns="qux"></a>') + def test_1463026_2_empty(self): + result = StringIO() + gen = XMLGenerator(result, short_empty_elements=True) + + gen.startDocument() + gen.startPrefixMapping(None, 'qux') + gen.startElementNS(('qux', 'a'), 'a', {}) + gen.endElementNS(('qux', 'a'), 'a') + gen.endPrefixMapping(None) + gen.endDocument() + + self.assertEquals(result.getvalue(), start+'<a xmlns="qux"/>') + def test_1463026_3(self): result = StringIO() gen = XMLGenerator(result) @@ -295,6 +371,20 @@ class XmlgenTest(unittest.TestCase): self.assertEquals(result.getvalue(), start+'<my:a xmlns:my="qux" b="c"></my:a>') + def test_1463026_3_empty(self): + result = StringIO() + gen = XMLGenerator(result, short_empty_elements=True) + + gen.startDocument() + gen.startPrefixMapping('my', 'qux') + gen.startElementNS(('qux', 'a'), 'a', {(None, 'b'):'c'}) + gen.endElementNS(('qux', 'a'), 'a') + gen.endPrefixMapping('my') + gen.endDocument() + + self.assertEquals(result.getvalue(), + start+'<my:a xmlns:my="qux" b="c"/>') + class XMLFilterBaseTest(unittest.TestCase): def test_filter_basic(self): |