Example #1
0
    def setUp(self):
        #~ dude = XCheck('dude')
        nick = BoolCheck('nick', required=False)
        fname = TextCheck('first', min_length = 1)
        fname.addattribute(nick)



        lname = TextCheck('last', min_length = 1)
        code = IntCheck('code', min_occurs = 1, max_occurs = 5)
        code.addattribute(TextCheck('word', required=False) )
        name = XCheck('name', children=[fname, lname, code])

        emailtype = SelectionCheck('type', values = ['home','work', 'personal'])
        email = EmailCheck('email', max_occurs=2)
        email.addattribute(emailtype)
        street = TextCheck('street')
        city = TextCheck('city')

        address = XCheck('address', children = [street, city, email], max_occurs = 4)
        self.address = address
        dude = XCheck('dude', children=[name, address])
        idch = IntCheck('id', required=True)
        dude.addattribute(idch)

        elem = ET.fromstring("""<dude id="1">
        <name>
            <first nick="true">Josh</first>
            <last>English</last>
            <code>12</code>
            <code word="answer">42</code>
        </name>
        <address>
            <street>100 Main St</street>
            <city>Podunk</city>
            <email type="home">[email protected]</email>
            <email type="work">[email protected]</email>
        </address>
        <address>
            <street>318 West Nowhere Ln</street>
            <city>East Podunk</city>
            <email type="personal">[email protected]</email>
        </address>
        </dude>""")
        self.w = Wrap(dude, elem)
Example #2
0
    def setUp(self):
        nick = BoolCheck('nick', required=False)
        fname = TextCheck('first', min_length = 1)
        fname.addattribute(nick)

        lname = TextCheck('last', min_length = 1)
        code = IntCheck('code', min_occurs = 1, max_occurs = 5)
        code.addattribute(TextCheck('word', required=False) )
        ch = XCheck('name', children=[fname, lname, code])
        idch = IntCheck('id', required=True)
        ch.addattribute(idch)
        elem = ET.fromstring("""<name id="1">
        <first nick="true">Josh</first>
        <last>English</last>
        <code>12</code>
        <code word="answer">42</code>
        </name>""")
        self.w = Wrap(ch, elem)
Example #3
0
 def test_bad_init(self):
     "Wrap should fail on initiation if element doesn't validate by checker"
     ch = TextCheck('name')
     elem = ET.fromstring('<idea>name</idea>')
     self.assertRaises(XCheckError, Wrap, ch, elem)
Example #4
0
 def testPassWithElement(self):
     "BoolCheck() accepts xml-formatting string"
     for x in ['true','yes','1','t','y','false','no','0','f','n']:
         self.assertTrue(self.b(ET.fromstring('<flag>%s</flag>' % x) ) )
Example #5
0
 def testPassWithElement(self):
     "SelectionCheck() accepts appropriate element.text"
     self.failUnless(self.s(ET.fromstring('<choice>alpha</choice>')))
Example #6
0
 def test_pass_with_element(self):
     self.failUnless(self.t(ET.fromstring("<test>4.5</test>")))
Example #7
0
 def test_fail_with_oob_element(self):
     "IntCheck() fails with element.text as out-of-bounds integer"
     self.assertRaises(self.t.error, self.t, ET.fromstring("<test>99</test>"))
Example #8
0
 def test_fail_with_float_elem(self):
     "IntCheck() raises ValueError with element.text as non-integral float"
     self.assertRaises(ValueError, self.t, ET.fromstring("<test>5.5</test>"))
Example #9
0
 def test_pass_with_element(self):
     "IntCheck() accepts valid element.text"
     self.failUnless(self.t(ET.fromstring("<test>4</test>")))