def test_from_string(self): text = '<DEFINE name="http.error.file.404" value="404.html" />' definition = Definition.from_string(text) self.assertTrue(isinstance(definition, DefinitionElement)) text = '<DEFINE name="x"><DEFINE value="y" /><DEFINE value="z" /></DEFINE>' definition = Definition.from_string(text) self.assertTrue(isinstance(definition, DefinitionTree))
def test_definition_tree(self): text = ''' <DEFINE> <DEFINE value="x" /> <DEFINE vlaue="y" /> <UNKNOWN> <CUSTOM /> </UNKNOWN> </DEFINE>''' definition = Definition.from_string(text) def_tree = definition.to_lxml_element() self.assertEqual(2, len(def_tree.findall('DEFINE'))) unknown = def_tree.findall('UNKNOWN') self.assertEqual(1, len(unknown)) unknown = unknown[0] custom = list(unknown) self.assertEqual(1, len(custom)) custom = custom[0] self.assertEqual('CUSTOM', custom.tag)
def test_bad_root_tag(self): text = '<ERROR name="http.error.file.404" value="404.html" />' self.assertEqual('ERROR', Definition.from_string(text).tag) self.assertEqual('ERROR', Definition.from_lxml_element( etree.XML(text)).tag)