def test_add_elem_if_needed(self): stuff_check = load_checker( """<xcheck name="stuff"> <children> <text name="item" min_occurs="0" max_occurs="4" /> </children> </xcheck> """) empty_example = Wrap(stuff_check) empty_example._set_elem_value('item','one') self.assertEqual(empty_example._get_elem_value('item'),'one')
def test_wrap_string(self): s = "<dude><first>Josh</first><last>English</last></dude>" dudecheck = load_checker( """<xcheck name='dude'> <children> <text name='first'/> <text name='last'/> </children> </xcheck> """) dudecheck(s) dude = Wrap(dudecheck) self.assertTrue(isinstance(dude, Wrap)) dude = Wrap(dudecheck, s) self.assertTrue(isinstance(dude, Wrap)) self.assertEqual(dude._get_elem_value('first'),'Josh')
if __name__=='__main__': from loader import load_checker from core import check_node story = load_checker("""<xcheck name="story"> <attributes> <text name="code" required="true"/> <decimal name="revision" required="false"/> </attributes> <children> <text name="title" /> <text name="pasttitle" min_occurs="0" max_occurs="99"/> <int name="wordcount" /> <selection name="status" values="treatment, draft, critique, on_market, sold, reprint, retired" /> <list name="genres" min_occurs="0" values="sf, fantasy, horror, lit, punk, realism"/> <list name="keywords" min_occurs="0"/> <text name="file" min_occurs="0"/> <xcheck name="history" min_occurs="0"> <text name="item" min_occurs="0" max_occurs="99"> <attributes> <datetime name="date"/> </attributes> </text> </xcheck> <text name="plot" min_occurs="0" /> </children> </xcheck> """) print story charlie = ET.fromstring("""<story code="charlie" > <title>Uncle Charlie Goes Swimming</title>