def test_set_content(): xml1 = XMLStruct('<top><child>hello</child><num>10</num></top>') xml2 = XMLStruct('<top><child>there</child><num>12</num></top>') assert xml1 != xml2 xml2.child = "hello" xml2.num = 10 assert xml1 == xml2 assert '<child>hello</child>' in xml2.dumps() assert '<num>10</num>' in xml2.dumps()
def test_set_attr(): xml1 = XMLStruct('<top><child name="child1">hello</child></top>') xml2 = XMLStruct('<top><child name="child2">hello</child></top>') assert xml1 != xml2 xml2.child["name"] = "child1" assert xml1 == xml2 xml2.child["foo"] = "bar" assert '<child foo="bar" name="child1">' in xml2.dumps()
def test_dumps1(): top = XMLStruct(_mydir + '/plant_catalog.xml') assert top.PLANT.dumps() == """<?xml version="1.0" encoding="UTF-8"?> <PLANT> <COMMON>Bloodroot</COMMON> <BOTANICAL>Sanguinaria canadensis</BOTANICAL> <description> Foo Bar </description> <ZONE>4</ZONE> <LIGHT>Mostly Shady</LIGHT> <PRICE>$2.44</PRICE> <AVAILABILITY>031599</AVAILABILITY> </PLANT> """ assert top.dumps()
def test_dumps2(): xml1 = XMLStruct('<top><child name="child1">hello</child></top>') assert xml1.dumps() == """<?xml version="1.0" encoding="UTF-8"?>