Beispiel #1
0
 def test_find_first_nested(self):
     XML = u'''<?xml version="1.0" ?>
     <topelement>
       <subelement id="1">
           <subelement id="2"/>
       </subelement>
     </topelement>
     '''
     dom = vmxml.parse_xml(XML)
     sub1 = vmxml.find_first(dom, 'subelement')  # outermost
     sub2 = vmxml.find_first(sub1, 'subelement')  # innermost
     last = vmxml.find_first(sub2, 'subelement')
     self.assertIsNot(sub2, last)
Beispiel #2
0
 def test_remove_child(self):
     top = vmxml.find_first(self._dom, 'topelement')
     hello = list(vmxml.find_all(top, 'hello'))
     old = hello[1]
     vmxml.remove_child(top, old)
     updated_hello = list(vmxml.find_all(top, 'hello'))
     hello = hello[:1] + hello[2:]
     self.assertEqual(updated_hello, hello)
Beispiel #3
0
 def test_find_all(self, start_tag, tag, number):
     dom = self._dom
     if start_tag is not None:
         dom = vmxml.find_first(self._dom, 'topelement')
     elements = vmxml.find_all(dom, tag)
     matches = [vmxml.tag(e) == tag for e in elements]
     self.assertTrue(all(matches))
     self.assertEqual(len(matches), number)
Beispiel #4
0
 def test_remove_child(self):
     top = vmxml.find_first(self._dom, 'topelement')
     hello = list(vmxml.find_all(top, 'hello'))
     old = hello[1]
     vmxml.remove_child(top, old)
     updated_hello = list(vmxml.find_all(top, 'hello'))
     hello = hello[:1] + hello[2:]
     self.assertEqual(updated_hello, hello)
Beispiel #5
0
 def test_find_all(self, start_tag, tag, number):
     dom = self._dom
     if start_tag is not None:
         dom = vmxml.find_first(self._dom, 'topelement')
     elements = vmxml.find_all(dom, tag)
     matches = [vmxml.tag(e) == tag for e in elements]
     self.assertTrue(all(matches))
     self.assertEqual(len(matches), number)
Beispiel #6
0
 def test_append_child(self):
     empty = vmxml.find_first(self._dom, 'empty')
     vmxml.append_child(empty, vmxml.Element('new'))
     self.assertIsNotNone(vmxml.find_first(self._dom, 'new', None))
     empty = vmxml.find_first(self._dom, 'empty')
     self.assertIsNotNone(vmxml.find_first(empty, 'new', None))
Beispiel #7
0
 def test_children(self, start_tag, tag, number):
     element = vmxml.find_first(self._dom, start_tag)
     self.assertEqual(len(list(vmxml.children(element, tag))), number)
Beispiel #8
0
 def test_text(self, tag, result):
     element = vmxml.find_first(self._dom, tag)
     text = vmxml.text(element)
     self.assertEqual(text, result)
Beispiel #9
0
 def test_append_child(self):
     empty = vmxml.find_first(self._dom, 'empty')
     vmxml.append_child(empty, vmxml.Element('new'))
     self.assertIsNotNone(vmxml.find_first(self._dom, 'new', None))
     empty = vmxml.find_first(self._dom, 'empty')
     self.assertIsNotNone(vmxml.find_first(empty, 'new', None))
Beispiel #10
0
 def test_children(self, start_tag, tag, number):
     element = vmxml.find_first(self._dom, start_tag)
     self.assertEqual(len(list(vmxml.children(element, tag))), number)
Beispiel #11
0
 def test_text(self, tag, result):
     element = vmxml.find_first(self._dom, tag)
     text = vmxml.text(element)
     self.assertEqual(text, result)