[Zope-Checkins] CVS: Zope3/lib/python/Schema/tests - testDictField.py:1.2 testListField.py:1.4 testStrField.py:1.2 testTupleField.py:1.4

Martijn Faassen faassen@vet.uu.nl
Sun, 14 Jul 2002 23:41:18 +0200


Stephan Richter wrote:
> > -        try:
> > -            field.validate(None)
> > -            field.validate({'a': 5.3})
> > -            field.validate({'a': 2, 'b': 2.3})
> > -        except ValidationError, e:
> > -            self.unexpectedValidationError(e)
> > +        #try:
> > +        field.validate(None)
> > +        field.validate({'a': 5.3})
> > +        field.validate({'a': 2, 'b': 2.3})
> 
> What's that? I had fixed the unit tests in my checkin already to display a 
> typical unit test. Here is how my version looked like (example):
> 
> def testValidateValueTypes(self):
>         field = Dictionary(id="field", title='Dictionary field',
>                            description='', readonly=0, required=0,
>                            value_types=(Integer, Float))
>         self.assertEqual(None, field.validate(None))
>         self.assertEqual({'a': 5.3} , field.validate({'a': 5.3}))
>         self.assertEqual({'a': 2, 'b': 2.3},
>                           field.validate( {'a': 2, 'b': 2.3} ))
>         self.assertRaisesErrorNames(ErrorNames.WrongContainedType,
>                                     field.validate, {1: ''} )
>         self.assertRaisesErrorNames(ErrorNames.WrongContainedType,
>                                     field.validate, {'a': ()} )

Validators don't return any values; we refactored this at the Zope3
sprint. Their contract is to either raise an error or to pass. They don't
return anything as they don't ever do any conversion. The assertEqual
therefore does not make any sense anymore -- we spent some time getting
them out at the sprint and now I spent some more time getting them
out *again*, which is why I sound so snippy. A particularly useless
activity. :)

The commented out section is leftover debugging code, though it gave me
the idea to actually not put in the try..except after all, as it gives
better diagnostics in case of a problem (we'll get an error instead of
a failure but that's okay).

I'll do a checkin taking the try..except out.

Regards,

Martijn