Show
Ignore:
Timestamp:
08/25/10 17:28:08 (21 months ago)
Author:
emuller
Message:

ParameterSchema? and basic validation implemented.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/parameter_set_schema_validation/test/test_validators.py

    r454 r456  
    4848                           'true': NeuroTools.parameters.validators.Subclass(type=bool),  
    4949                           'yourlist': NeuroTools.parameters.validators.Subclass(type=list),  
    50                            'ps2': {'ps.a': NeuroTools.parameters.validators.Subclass(type=int),  
    51                                    'c': NeuroTools.parameters.validators.Subclass(type=int),  
    52                                    'ps.b': NeuroTools.parameters.validators.Subclass(type=int)}, 'null': NeuroTools.parameters.validators.Subclass(type=NoneType), 'mydict': {'c': NeuroTools.parameters.validators.Subclass(type=int), 'd': NeuroTools.parameters.validators.Subclass(type=int)}, 'hello': NeuroTools.parameters.validators.Subclass(type=str)} 
     50                           'ps2': {'ps': {'a':NeuroTools.parameters.validators.Subclass(type=int), 
     51                                          'b':NeuroTools.parameters.validators.Subclass(type=int)}, 
     52                                   'c': NeuroTools.parameters.validators.Subclass(type=int)},  
     53                           'null': NeuroTools.parameters.validators.Subclass(type=type(None)), 
     54                           'mydict': {'c': NeuroTools.parameters.validators.Subclass(type=int), 
     55                                      'd': NeuroTools.parameters.validators.Subclass(type=int)}, 
     56                           'hello': NeuroTools.parameters.validators.Subclass(type=str)}) 
    5357 
    5458 
     
    6367 
    6468 
     69    def test_validate_generated_schema(self): 
     70        s1 = ParameterSchema(ps3) 
     71 
     72        v = CongruencyValidator() 
     73        assert v.validate(ps3,s1)==True 
     74         
    6575    def test_simple_validate(self): 
     76        v = CongruencyValidator() 
     77        assert v.validate(ps3,schema3)==True 
     78 
     79    def test_validation_failure_info(self): 
     80        """ Test the error output for an failed validation against a schema""" 
     81 
    6682        s1 = ParameterSchema(ps3) 
    67         print s1 
    68         #print ps3.flatten() 
    6983         
     84        s1.ps2.ps.a = Subclass(type=float) 
     85        v = CongruencyValidator() 
     86        r = False 
     87        try: 
     88            r = v.validate(ps3,s1) 
     89        except Exception as e: 
     90            assert isinstance(e,ValidationError) 
     91            assert e.path=='ps2.ps.a' 
     92            assert e.parameter==ps3.ps2.ps.a 
     93            assert e.schema_base==s1.ps2.ps.a 
     94        assert r==False 
    7095 
    7196    def test_congruent_dicts(self):