def test_nested_element(self): result = flatten_xml_from_string('<a><b/></a>') expected = [ ['a'], ['a', 'b'], ] self.assertEqual(result, expected)
def test_triple_nested(self): result = flatten_xml_from_string('<a><b><c/><d/></b><e/></a>') expected = [ ['a'], ['a', 'b'], ['a', 'b', 'c'], ['a', 'b', 'd'], ['a', 'e'], ] self.assertEqual(result, expected)
def test_with_text_multiple(self): result = flatten_xml_from_string('<a>foo<b>bar</b><b>baz</b></a>', ) expected = [ ['a'], ['a', '!foo'], ['a', 'b'], ['a', 'b', '!bar'], ['a', 'b'], ['a', 'b', '!baz'], ] self.assertEqual(result, expected)
def test_with_text_multiple(self): result = flatten_xml_from_string( '<a>foo<b>bar</b><b>baz</b></a>', ) expected = [ ['a'], ['a', '!foo'], ['a', 'b'], ['a', 'b', '!bar'], ['a', 'b'], ['a', 'b', '!baz'], ] self.assertEqual(result, expected)
def test_with_text_and_tail(self): result = flatten_xml_from_string( '<a>foo<b>bar</b>baz<c>cat</c>dog</a>', ) expected = [ ['a'], ['a', '!foo'], ['a', 'b'], ['a', 'b', '!bar'], ['a', '!baz'], ['a', 'c'], ['a', 'c', '!cat'], ['a', '!dog'], ] self.assertEqual(result, expected)
def test_single_element(self): result = flatten_xml_from_string('<p/>') expected = [ ['p'], ] self.assertEqual(result, expected)
def test_empty_string(self): result = flatten_xml_from_string('') self.assertEqual(result, '')