Changeset 237

Show
Ignore:
Timestamp:
07/04/06 16:08:25 (3 years ago)
Author:
matt
Message:

Check the number of values Composite is asked to validate to ensure that the
final dict will be correct.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/composite/formal/examples/composite.py

    r236 r237  
    2727 
    2828    def validate(self, value): 
     29 
     30        # Check we have the correct number of values, otherwise the final value 
     31        # could be completely wrong because we're relying on zip to build the 
     32        # dict. 
     33        if len(value) != len(self.composition): 
     34            raise ValueError("Incorrect number of values to validate") 
    2935 
    3036        # If nothing has been entered then we'll have a sequence of None 
  • branches/composite/formal/test/test_types.py

    r236 r237  
    252252            ('bar', formal.Integer(required=True)) 
    253253            ], required=True).validate, [u'foo', None]) 
     254 
     255    def test_wrongNumberOfValues(self): 
     256        self.assertRaises(ValueError, Composite([ 
     257            ('foo', formal.Integer()), 
     258            ('bar', formal.String()), 
     259            ]).validate, [123]) 
     260