def test_dict_to_elementtree6(self): test_data = { "child1$converted$": "Value1", "child2": "Value2", "child3": { "child31": "Value31", "child32$converted$": "Value32", "child33": "Value33", "child34": { "child341$converted$": "Value341" } } } root = Element("root") child2 = SubElement(root, "child2") child2.text = "Value2" child3 = SubElement(root, "child3") child31 = SubElement(child3, "child31") child31.text = "Value31" child33 = SubElement(child3, "child33") child33.text = "Value33" expected_result = root result = Element("root") convert_dict_to_elementtree(test_data, result) self.assertTrue(elements_equal(result, expected_result))
def test_dict_to_elementtree5(self): test_data = { "child2$converted$": ["Value1" "Value2", "Value3", "Value4"] } root = Element("root") expected_result = root result = Element("root") convert_dict_to_elementtree(test_data, result) self.assertTrue(elements_equal(result, expected_result))
def test_dict_to_elementtree2(self): test_data = {"child1": {"child11": {"child111": "Value"}}} root = Element("root") child1 = SubElement(root, "child1") child11 = SubElement(child1, "child11") child111 = SubElement(child11, "child111") child111.text = "Value" expected_result = root result = Element("root") convert_dict_to_elementtree(test_data, result) self.assertTrue(elements_equal(result, expected_result))
def test_element_equal_wide_different(self): root1 = Element("root") child1 = SubElement(root1, "child1") child11 = SubElement(root1, "child11") child111 = SubElement(root1, "child111") child1.set("attrib1", "value1") child1.set("attrib11", "value1") child111.text = "text1" root2 = Element("root") child2 = SubElement(root2, "child1") child22 = SubElement(root2, "child11") child222 = SubElement(root2, "child111") child2.set("attrib1", "value1") child2.set("attrib12", "value1") child222.text = "text1" self.assertFalse(elements_equal(root1, root2))
def test_dict_to_elementtree4(self): test_data = { "child1": { "@attr1": "attr-value1", "child11": { "@attr11": "attr-value11", "child111": { "#text": "Value", "@attr111": "attr-value111" } } }, "child2": [{ "@attr2": "attr-value2", "#text": "Value2" }, { "@attr2": "attr-value2", "#text": "Value3" }, { "@attr2": "attr-value2", "#text": "Value4" }] } root = Element("root") child1 = SubElement(root, "child1") child1.set("attr1", "attr-value1") child11 = SubElement(child1, "child11") child11.set("attr11", "attr-value11") child111 = SubElement(child11, "child111") child111.set("attr111", "attr-value111") child111.text = "Value" child2 = SubElement(root, "child2") child2.set("attr2", "attr-value2") child2.text = "Value2" child2_second = SubElement(root, "child2") child2_second.set("attr2", "attr-value2") child2_second.text = "Value3" child2_third = SubElement(root, "child2") child2_third.set("attr2", "attr-value2") child2_third.text = "Value4" expected_result = root result = Element("root") convert_dict_to_elementtree(test_data, result) self.assertTrue(elements_equal(result, expected_result))
def test_elements_equal_deep_different(self): root1 = Element("root") child1 = SubElement(root1, "child1") child1.set("attr", "attr") child1.text = "Value" child11 = SubElement(child1, "child11") child111 = SubElement(child11, "child111") child111.text = "Value" child1111 = SubElement(child111, "child1111") child1111.set("attrib", "attrib") root2 = Element("root") child2 = SubElement(root2, "child1") child2.set("attr", "attr") child2.text = "Value" child22 = SubElement(child2, "chi!!difference!!ld11") child222 = SubElement(child22, "child111") child222.text = "Value" child2222 = SubElement(child222, "child1111") child2222.set("attrib", "attrib") self.assertFalse(elements_equal(root1, root2))
def test_elements_equal_deep_same(self): root1 = Element("root") child1 = SubElement(root1, "child1") child1.set("attr", "attr") child1.text = "Value" child11 = SubElement(child1, "child11") child111 = SubElement(child11, "child111") child111.text = "Value" child1111 = SubElement(child111, "child1111") child1111.set("attrib", "attrib") root2 = Element("root") child2 = SubElement(root2, "child1") child2.set("attr", "attr") child2.text = "Value" child22 = SubElement(child2, "child11") child222 = SubElement(child22, "child111") child222.text = "Value" child2222 = SubElement(child222, "child1111") child2222.set("attrib", "attrib") self.assertTrue(elements_equal(root1, root2))
def test_dict_to_elementtree(self): test_data = { "child1": "Value1", "child2": [ "Value2", "Value3", "Value4", ] } root = Element("root") child1 = SubElement(root, "child1") child1.text = "Value1" child2 = SubElement(root, "child2") child2.text = "Value2" child2_second = SubElement(root, "child2") child2_second.text = "Value3" child2_third = SubElement(root, "child2") child2_third.text = "Value4" expected_result = root result = Element("root") convert_dict_to_elementtree(test_data, result) self.assertTrue(elements_equal(result, expected_result))
def test_elements_equal_same_root(self): root1 = Element("root") root2 = Element("root") self.assertTrue(elements_equal(root1, root2))
def test_elements_equal_different_root(self): root1 = Element("root") root2 = Element("different") self.assertFalse(elements_equal(root1, root2))