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)
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)
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)
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))
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)
def test_text(self, tag, result): element = vmxml.find_first(self._dom, tag) text = vmxml.text(element) self.assertEqual(text, result)