Ejemplo n.º 1
0
    def testText(self):
        s = formless.Text()
        self.assertEqual(process(s, ""), None)
        self.assertEqual(process(s, "Fooo"), "Fooo")
        self.assertEqual(process(s, "This is a string"), "This is a string")
        self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\xc3\xa9sar')

        s = formless.Text(str=True)
        self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\u00e9sar')

        s = formless.Text(required=True)
        self.assertRaises(formless.InputError, process, s, "")
        
        s = formless.Text(required=False)
        self.assertEqual(process(s, "Bar"), "Bar")
        self.assertEqual(process(s, ""), None)
        
        s = formless.Text()
        self.assertEqual(process(s, ' abc '), ' abc ')
        
        s = formless.Text(strip=True, required=True)
        self.assertEqual(process(s, ' abc '), 'abc')
        self.assertRaises(formless.InputError, process, s, ' ')
        
        s = formless.Text(required=False, strip=True)
        self.assertEqual(process(s, ' abc '), 'abc')
        self.assertEqual(process(s, ' '), None)
Ejemplo n.º 2
0
    def testText(self):
        s = formless.Text()
        self.assertEqual(process(s, ""), None)
        self.assertEqual(process(s, "Fooo"), "Fooo")
        self.assertEqual(process(s, "This is a string"), "This is a string")
        self.assertEqual(process(s, b'C\xc3\xa9sar'), 'C\xc3\xa9sar')
        self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\xc3\xa9sar')

#       I'm not sure what functionality was intended here, and I can't
#       see how it was implemented.  Let's assume we don't want it
#       any more -- MD 2018-08
#        s = formless.Text(str=True)
#        self.assertEqual(process(s, 'C\xc3\xa9sar'), 'C\u00e9sar')

        s = formless.Text(required=True)
        self.assertRaises(formless.InputError, process, s, "")
        
        s = formless.Text(required=False)
        self.assertEqual(process(s, "Bar"), "Bar")
        self.assertEqual(process(s, ""), None)
        
        s = formless.Text()
        self.assertEqual(process(s, ' abc '), ' abc ')
        
        s = formless.Text(strip=True, required=True)
        self.assertEqual(process(s, ' abc '), 'abc')
        self.assertRaises(formless.InputError, process, s, ' ')
        
        s = formless.Text(required=False, strip=True)
        self.assertEqual(process(s, ' abc '), 'abc')
        self.assertEqual(process(s, ' '), None)
Ejemplo n.º 3
0
 class Test(formless.TypedInterface):
     foo = formless.String()
     bar = formless.Text()
     baz = formless.Integer()
     quux = formless.Object(interface=_indirectOther())