def test_readpairs_4 (self) : r = StringIO.StringIO("<root><child/></root>\n\n<root></root>\n<root></root><child></child>") b = read_pairs(r) self.assert_(len(b) == 2)
def test_readpairs_3 (self) : r = StringIO.StringIO("") b = read_pairs(r) self.assert_(len(b) == 0)
def test_readpairs_1 (self) : r = StringIO.StringIO("<root><one></one><two></two></root>") b = read_pairs(r) self.assert_(b == []) self.assert_(len(b) == 0)
def test_readpairs_2 (self) : r = StringIO.StringIO("<root><one></one><two></two></root>\n<one></one>") b = read_pairs(r) self.assert_(len(b) == 1)
# ---------------- # Test XML strings # ---------------- # Define strings # Single pair string_1 = "<root><one></one><three></three><two></two><four></four></root>\n<one></one>" string_2 = "<root><one></one><three></three><two></two><four></four></root>\n<three></three>" string_3 = "<root><one><five></five></one><three><one></one></three><two></two><four><one><five></five></one></four></root>\n<one><five></five></one>" # Multiple pairs string_4 = string_1 + string_2 string_5 = string_4 + string_3 # Create test XMLs from strings test_xml_1 = read_pairs(StringIO.StringIO(string_1)) test_xml_2 = read_pairs(StringIO.StringIO(string_2)) test_xml_3 = read_pairs(StringIO.StringIO(string_3)) test_xml_4 = read_pairs(StringIO.StringIO(string_4)) test_xml_5 = read_pairs(StringIO.StringIO(string_5)) class TestXML (unittest.TestCase) : # --------- # read_input # --------- def test_read_1 (self) : r = StringIO.StringIO("<root></root>\n") b = read_input(r) self.assert_(b == "<root></root>\n")