Back to index

python3.2  3.2.2
Public Member Functions
test.test_sax.XmlgenTest Class Reference

List of all members.

Public Member Functions

def test_xmlgen_basic
def test_xmlgen_basic_empty
def test_xmlgen_content
def test_xmlgen_content_empty
def test_xmlgen_pi
def test_xmlgen_content_escape
def test_xmlgen_attr_escape
def test_xmlgen_ignorable
def test_xmlgen_ignorable_empty
def test_xmlgen_ns
def test_xmlgen_ns_empty
def test_1463026_1
def test_1463026_1_empty
def test_1463026_2
def test_1463026_2_empty
def test_1463026_3
def test_1463026_3_empty
def test_5027_1
def test_5027_2

Detailed Description

Definition at line 163 of file test_sax.py.


Member Function Documentation

Definition at line 313 of file test_sax.py.

00313 
00314     def test_1463026_1(self):
00315         result = StringIO()
00316         gen = XMLGenerator(result)
00317 
00318         gen.startDocument()
00319         gen.startElementNS((None, 'a'), 'a', {(None, 'b'):'c'})
00320         gen.endElementNS((None, 'a'), 'a')
00321         gen.endDocument()
00322 
00323         self.assertEqual(result.getvalue(), start+'<a b="c"></a>')

Here is the call graph for this function:

Definition at line 324 of file test_sax.py.

00324 
00325     def test_1463026_1_empty(self):
00326         result = StringIO()
00327         gen = XMLGenerator(result, short_empty_elements=True)
00328 
00329         gen.startDocument()
00330         gen.startElementNS((None, 'a'), 'a', {(None, 'b'):'c'})
00331         gen.endElementNS((None, 'a'), 'a')
00332         gen.endDocument()
00333 
00334         self.assertEqual(result.getvalue(), start+'<a b="c"/>')

Here is the call graph for this function:

Definition at line 335 of file test_sax.py.

00335 
00336     def test_1463026_2(self):
00337         result = StringIO()
00338         gen = XMLGenerator(result)
00339 
00340         gen.startDocument()
00341         gen.startPrefixMapping(None, 'qux')
00342         gen.startElementNS(('qux', 'a'), 'a', {})
00343         gen.endElementNS(('qux', 'a'), 'a')
00344         gen.endPrefixMapping(None)
00345         gen.endDocument()
00346 
00347         self.assertEqual(result.getvalue(), start+'<a xmlns="qux"></a>')

Here is the call graph for this function:

Definition at line 348 of file test_sax.py.

00348 
00349     def test_1463026_2_empty(self):
00350         result = StringIO()
00351         gen = XMLGenerator(result, short_empty_elements=True)
00352 
00353         gen.startDocument()
00354         gen.startPrefixMapping(None, 'qux')
00355         gen.startElementNS(('qux', 'a'), 'a', {})
00356         gen.endElementNS(('qux', 'a'), 'a')
00357         gen.endPrefixMapping(None)
00358         gen.endDocument()
00359 
00360         self.assertEqual(result.getvalue(), start+'<a xmlns="qux"/>')

Here is the call graph for this function:

Definition at line 361 of file test_sax.py.

00361 
00362     def test_1463026_3(self):
00363         result = StringIO()
00364         gen = XMLGenerator(result)
00365 
00366         gen.startDocument()
00367         gen.startPrefixMapping('my', 'qux')
00368         gen.startElementNS(('qux', 'a'), 'a', {(None, 'b'):'c'})
00369         gen.endElementNS(('qux', 'a'), 'a')
00370         gen.endPrefixMapping('my')
00371         gen.endDocument()
00372 
00373         self.assertEqual(result.getvalue(),
00374             start+'<my:a xmlns:my="qux" b="c"></my:a>')

Here is the call graph for this function:

Definition at line 375 of file test_sax.py.

00375 
00376     def test_1463026_3_empty(self):
00377         result = StringIO()
00378         gen = XMLGenerator(result, short_empty_elements=True)
00379 
00380         gen.startDocument()
00381         gen.startPrefixMapping('my', 'qux')
00382         gen.startElementNS(('qux', 'a'), 'a', {(None, 'b'):'c'})
00383         gen.endElementNS(('qux', 'a'), 'a')
00384         gen.endPrefixMapping('my')
00385         gen.endDocument()
00386 
00387         self.assertEqual(result.getvalue(),
00388             start+'<my:a xmlns:my="qux" b="c"/>')

Here is the call graph for this function:

Definition at line 389 of file test_sax.py.

00389 
00390     def test_5027_1(self):
00391         # The xml prefix (as in xml:lang below) is reserved and bound by
00392         # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
00393         # a bug whereby a KeyError is thrown because this namespace is missing
00394         # from a dictionary.
00395         #
00396         # This test demonstrates the bug by parsing a document.
00397         test_xml = StringIO(
00398             '<?xml version="1.0"?>'
00399             '<a:g1 xmlns:a="http://example.com/ns">'
00400              '<a:g2 xml:lang="en">Hello</a:g2>'
00401             '</a:g1>')
00402 
00403         parser = make_parser()
00404         parser.setFeature(feature_namespaces, True)
00405         result = StringIO()
00406         gen = XMLGenerator(result)
00407         parser.setContentHandler(gen)
00408         parser.parse(test_xml)
00409 
00410         self.assertEqual(result.getvalue(),
00411                          start + (
00412                          '<a:g1 xmlns:a="http://example.com/ns">'
00413                           '<a:g2 xml:lang="en">Hello</a:g2>'
00414                          '</a:g1>'))

Here is the call graph for this function:

Definition at line 415 of file test_sax.py.

00415 
00416     def test_5027_2(self):
00417         # The xml prefix (as in xml:lang below) is reserved and bound by
00418         # definition to http://www.w3.org/XML/1998/namespace.  XMLGenerator had
00419         # a bug whereby a KeyError is thrown because this namespace is missing
00420         # from a dictionary.
00421         #
00422         # This test demonstrates the bug by direct manipulation of the
00423         # XMLGenerator.
00424         result = StringIO()
00425         gen = XMLGenerator(result)
00426 
00427         gen.startDocument()
00428         gen.startPrefixMapping('a', 'http://example.com/ns')
00429         gen.startElementNS(('http://example.com/ns', 'g1'), 'g1', {})
00430         lang_attr = {('http://www.w3.org/XML/1998/namespace', 'lang'): 'en'}
00431         gen.startElementNS(('http://example.com/ns', 'g2'), 'g2', lang_attr)
00432         gen.characters('Hello')
00433         gen.endElementNS(('http://example.com/ns', 'g2'), 'g2')
00434         gen.endElementNS(('http://example.com/ns', 'g1'), 'g1')
00435         gen.endPrefixMapping('a')
00436         gen.endDocument()
00437 
00438         self.assertEqual(result.getvalue(),
00439                          start + (
00440                          '<a:g1 xmlns:a="http://example.com/ns">'
00441                           '<a:g2 xml:lang="en">Hello</a:g2>'
00442                          '</a:g1>'))
00443 

Here is the call graph for this function:

Definition at line 233 of file test_sax.py.

00233 
00234     def test_xmlgen_attr_escape(self):
00235         result = StringIO()
00236         gen = XMLGenerator(result)
00237 
00238         gen.startDocument()
00239         gen.startElement("doc", {"a": '"'})
00240         gen.startElement("e", {"a": "'"})
00241         gen.endElement("e")
00242         gen.startElement("e", {"a": "'\""})
00243         gen.endElement("e")
00244         gen.startElement("e", {"a": "\n\r\t"})
00245         gen.endElement("e")
00246         gen.endElement("doc")
00247         gen.endDocument()
00248 
00249         self.assertEqual(result.getvalue(), start +
00250             ("<doc a='\"'><e a=\"'\"></e>"
00251              "<e a=\"'&quot;\"></e>"
00252              "<e a=\"&#10;&#13;&#9;\"></e></doc>"))

Here is the call graph for this function:

Definition at line 164 of file test_sax.py.

00164 
00165     def test_xmlgen_basic(self):
00166         result = StringIO()
00167         gen = XMLGenerator(result)
00168         gen.startDocument()
00169         gen.startElement("doc", {})
00170         gen.endElement("doc")
00171         gen.endDocument()
00172 
00173         self.assertEqual(result.getvalue(), start + "<doc></doc>")

Here is the call graph for this function:

Definition at line 174 of file test_sax.py.

00174 
00175     def test_xmlgen_basic_empty(self):
00176         result = StringIO()
00177         gen = XMLGenerator(result, short_empty_elements=True)
00178         gen.startDocument()
00179         gen.startElement("doc", {})
00180         gen.endElement("doc")
00181         gen.endDocument()
00182 
00183         self.assertEqual(result.getvalue(), start + "<doc/>")

Here is the call graph for this function:

Definition at line 184 of file test_sax.py.

00184 
00185     def test_xmlgen_content(self):
00186         result = StringIO()
00187         gen = XMLGenerator(result)
00188 
00189         gen.startDocument()
00190         gen.startElement("doc", {})
00191         gen.characters("huhei")
00192         gen.endElement("doc")
00193         gen.endDocument()
00194 
00195         self.assertEqual(result.getvalue(), start + "<doc>huhei</doc>")

Here is the call graph for this function:

Definition at line 196 of file test_sax.py.

00196 
00197     def test_xmlgen_content_empty(self):
00198         result = StringIO()
00199         gen = XMLGenerator(result, short_empty_elements=True)
00200 
00201         gen.startDocument()
00202         gen.startElement("doc", {})
00203         gen.characters("huhei")
00204         gen.endElement("doc")
00205         gen.endDocument()
00206 
00207         self.assertEqual(result.getvalue(), start + "<doc>huhei</doc>")

Here is the call graph for this function:

Definition at line 220 of file test_sax.py.

00220 
00221     def test_xmlgen_content_escape(self):
00222         result = StringIO()
00223         gen = XMLGenerator(result)
00224 
00225         gen.startDocument()
00226         gen.startElement("doc", {})
00227         gen.characters("<huhei&")
00228         gen.endElement("doc")
00229         gen.endDocument()
00230 
00231         self.assertEqual(result.getvalue(),
00232             start + "<doc>&lt;huhei&amp;</doc>")

Here is the call graph for this function:

Definition at line 253 of file test_sax.py.

00253 
00254     def test_xmlgen_ignorable(self):
00255         result = StringIO()
00256         gen = XMLGenerator(result)
00257 
00258         gen.startDocument()
00259         gen.startElement("doc", {})
00260         gen.ignorableWhitespace(" ")
00261         gen.endElement("doc")
00262         gen.endDocument()
00263 
00264         self.assertEqual(result.getvalue(), start + "<doc> </doc>")

Here is the call graph for this function:

Definition at line 265 of file test_sax.py.

00265 
00266     def test_xmlgen_ignorable_empty(self):
00267         result = StringIO()
00268         gen = XMLGenerator(result, short_empty_elements=True)
00269 
00270         gen.startDocument()
00271         gen.startElement("doc", {})
00272         gen.ignorableWhitespace(" ")
00273         gen.endElement("doc")
00274         gen.endDocument()
00275 
00276         self.assertEqual(result.getvalue(), start + "<doc> </doc>")

Here is the call graph for this function:

Definition at line 277 of file test_sax.py.

00277 
00278     def test_xmlgen_ns(self):
00279         result = StringIO()
00280         gen = XMLGenerator(result)
00281 
00282         gen.startDocument()
00283         gen.startPrefixMapping("ns1", ns_uri)
00284         gen.startElementNS((ns_uri, "doc"), "ns1:doc", {})
00285         # add an unqualified name
00286         gen.startElementNS((None, "udoc"), None, {})
00287         gen.endElementNS((None, "udoc"), None)
00288         gen.endElementNS((ns_uri, "doc"), "ns1:doc")
00289         gen.endPrefixMapping("ns1")
00290         gen.endDocument()
00291 
00292         self.assertEqual(result.getvalue(), start + \
00293            ('<ns1:doc xmlns:ns1="%s"><udoc></udoc></ns1:doc>' %
00294                                          ns_uri))

Here is the call graph for this function:

Definition at line 295 of file test_sax.py.

00295 
00296     def test_xmlgen_ns_empty(self):
00297         result = StringIO()
00298         gen = XMLGenerator(result, short_empty_elements=True)
00299 
00300         gen.startDocument()
00301         gen.startPrefixMapping("ns1", ns_uri)
00302         gen.startElementNS((ns_uri, "doc"), "ns1:doc", {})
00303         # add an unqualified name
00304         gen.startElementNS((None, "udoc"), None, {})
00305         gen.endElementNS((None, "udoc"), None)
00306         gen.endElementNS((ns_uri, "doc"), "ns1:doc")
00307         gen.endPrefixMapping("ns1")
00308         gen.endDocument()
00309 
00310         self.assertEqual(result.getvalue(), start + \
00311            ('<ns1:doc xmlns:ns1="%s"><udoc/></ns1:doc>' %
00312                                          ns_uri))

Here is the call graph for this function:

Definition at line 208 of file test_sax.py.

00208 
00209     def test_xmlgen_pi(self):
00210         result = StringIO()
00211         gen = XMLGenerator(result)
00212 
00213         gen.startDocument()
00214         gen.processingInstruction("test", "data")
00215         gen.startElement("doc", {})
00216         gen.endElement("doc")
00217         gen.endDocument()
00218 
00219         self.assertEqual(result.getvalue(), start + "<?test data?><doc></doc>")

Here is the call graph for this function:


The documentation for this class was generated from the following file: