def test_parse_with_file_path(self): """Parse with file path""" fname = tempfile.mktemp(".xml") fout = open(fname, "w") fout.write(MONTY_XML) fout.close() doc = parse(fname) self.run_checks(doc)
def Xtest_parse_with_url(self): doc = parse(TEST_URL) # Minimal node testing self.assertEqual(len(doc.xml_children), 1) self.assertEqual(doc.xml_children[0].xml_type, tree.element.xml_type) self.assertEqual(doc.xml_children[0].xml_qname, "disclaimer") self.assertEqual(doc.xml_children[0].xml_namespace, None) self.assertEqual(doc.xml_children[0].xml_prefix, None)
def test_parse_with_file_path(self): """Parse with file path""" fname = tempfile.mktemp('.xml') fout = open(fname, 'w') fout.write(MONTY_XML) fout.close() doc = parse(fname) self.run_checks(doc)
def test_dom(self): doc = dom.parse(self.MONTY_XML) for p, line in zip(doc.getElementsByTagNameNS(None, u"python"), self.lines_py): #A generator output = cStringIO.StringIO() xml_print(p, stream=output) self.assertEqual(output.getvalue(), line) p1 = doc.getElementsByTagNameNS(None, u"python").next() self.assertEqual(p1.getAttributeNS(None, u'spam'), u'eggs')
def test_parse_with_stream(self): """Parse with stream""" fname = tempfile.mktemp(".xml") fout = open(fname, "w") fout.write(MONTY_XML) fout.close() fout = open(fname, "r") doc = parse(fout) fout.close() self.run_checks(doc)
def test_parse_with_stream(self): """Parse with stream""" fname = tempfile.mktemp('.xml') fout = open(fname, 'w') fout.write(MONTY_XML) fout.close() fout = open(fname, 'r') doc = parse(fout) fout.close() self.run_checks(doc)
def Xtest_parse_with_url(self): doc = parse(TEST_URL) #Minimal node testing self.assertEqual(len(doc.xml_children), 1) self.assertEqual(doc.xml_children[0].xml_type, tree.element.xml_type) self.assertEqual(doc.xml_children[0].xml_qname, 'disclaimer') self.assertEqual(doc.xml_children[0].xml_namespace, None) self.assertEqual( doc.xml_children[0].xml_prefix, None, )
def test_ticket_8(self): "Test for ticket #8 bug" text = '<row a="" b="" c="" d="" e="" f=""/>' doc = parse(text) row = doc.xml_select("row")[0] attrs = row.xml_attributes # Verify that attributemap_contains returns a sane result; # for each K in attrs.keys(), 'K in attrs' is true. # for a few values of K not in attrs.keys(), 'K in attrs' is false. for k in attrs.keys(): self.assertTrue(k in attrs) for k in [(None, "g"), (None, "h"), (None, "z")]: self.assertFalse(k in attrs)
def test_ticket_8(self): "Test for ticket #8 bug" text = '<row a="" b="" c="" d="" e="" f=""/>' doc = parse(text) row = doc.xml_select("row")[0] attrs = row.xml_attributes # Verify that attributemap_contains returns a sane result; # for each K in attrs.keys(), 'K in attrs' is true. # for a few values of K not in attrs.keys(), 'K in attrs' is false. for k in attrs.keys(): self.assertTrue(k in attrs) for k in [(None, 'g'), (None, 'h'), (None, 'z')]: self.assertFalse(k in attrs)
def test_parse_with_string(self): """Parse with string""" doc = parse(MONTY_XML) self.run_checks(doc)
for p in doc.monty.python: # The loop will pick up both python elements xml_print(p) print print print "---------" "DOM" from amara import dom from amara import xml_print MONTY_XML = """<monty> <python spam="eggs">What do you mean "bleh"</python> <python ministry="abuse">But I was looking for argument</python> </monty>""" doc = dom.parse(MONTY_XML) for p in doc.getElementsByTagNameNS(None, u"python"): # A generator xml_print(p) print p1 = doc.getElementsByTagNameNS(None, u"python").next() print p1.getAttributeNS(None, u"spam") print print "---------" "XPath" from amara import bindery from amara import xml_print MONTY_XML = """<monty> <python spam="eggs">What do you mean "bleh"</python>
for p in doc.monty.python: #The loop will pick up both python elements xml_print(p) print print print '---------' 'DOM' from amara import dom from amara import xml_print MONTY_XML = """<monty> <python spam="eggs">What do you mean "bleh"</python> <python ministry="abuse">But I was looking for argument</python> </monty>""" doc = dom.parse(MONTY_XML) for p in doc.getElementsByTagNameNS(None, u"python"): #A generator xml_print(p) print p1 = doc.getElementsByTagNameNS(None, u"python").next() print p1.getAttributeNS(None, u'spam') print print '---------' 'XPath' from amara import bindery from amara import xml_print MONTY_XML = """<monty> <python spam="eggs">What do you mean "bleh"</python>