示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
 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')
示例#5
0
 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')
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
 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,
     )
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
 def test_parse_with_string(self):
     """Parse with string"""
     doc = parse(MONTY_XML)
     self.run_checks(doc)
示例#12
0
文件: day2.py 项目: abed-hawa/amara
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>
示例#13
0
文件: day2.py 项目: mredar/amara
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>
示例#14
0
 def test_parse_with_string(self):
     """Parse with string"""
     doc = parse(MONTY_XML)
     self.run_checks(doc)