Changeset 474

Show
Ignore:
Timestamp:
11/02/10 17:49:15 (19 months ago)
Author:
emuller
Message:

Test Eval and Subclass Schema validators from yaml

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/test/test_validators.py

    r465 r474  
    100100        assert r == False 
    101101 
     102    def test_complex_eval(self): 
     103 
     104        p_str = """ 
     105        list: [1,2,3,4] 
     106        flist: [1.0,2.0,3.0,4.0] 
     107        """ 
     108 
     109        s_str = """ 
     110        list: !!python/object:NeuroTools.parameters.validators.Eval { expr: 'isinstance(x,list) and all([isinstance(elem,int) for elem in x])', var: 'x'} 
     111        flist: !!python/object:NeuroTools.parameters.validators.Eval { expr: 'isinstance(x,list) and all([isinstance(elem,float) for elem in x])', var: 'x'} 
     112        """ 
     113         
     114         
     115        s1 = ParameterSchema(yaml.load(s_str)) 
     116        p1 = ParameterSet(yaml.load(p_str)) 
     117 
     118        v = CongruencyValidator() 
     119        # test Eval which checks for isinstance(x,list) 
     120        #s1.mylist = NeuroTools.parameters.validators.Eval('isinstance(x,list) and all([isinstance(elem,int) for elem in x])',var='x') 
     121        assert v.validate(p1,s1)==True 
     122 
     123 
    102124 
    103125    def test_simple_validate(self): 
     
    135157           all: /somewhere1/path1.xml 
    136158           specific: /somewhere2/path2.xml 
     159        numbers: 
     160           float: 1.0 
    137161        """ 
    138162 
    139163        schema_str = """ 
    140164        # user info 
    141         username: Subclass(type=str) 
    142         email:  Subclass(type=str) 
    143  
    144         # recipes 
    145         recipes: 
    146            all: Subclass(type=str) 
    147            specific: Subclass(type=str) 
     165        username: '' 
     166        email:  '' 
     167 
     168        # recipes 
     169        recipes: 
     170           all: '' 
     171           specific: '' 
     172        numbers: 
     173           float: !!python/object:NeuroTools.parameters.validators.Subclass { type: !!python/name:float } 
    148174        """ 
    149175 
     
    179205           all: /somewhere1/path1.xml 
    180206           specific: /somewhere2/path2.xml 
     207        numbers: 
     208           float: 1.0 
    181209        """ 
    182210 
    183211        schema_str = """ 
    184212        # user info 
    185         username: Subclass(type=str) 
    186         email:  Subclass(type=str) 
    187  
    188         # recipes 
    189         recipes: 
    190            all: Subclass(type=str) 
    191            specific: Subclass(type=str) 
     213        username: '' 
     214        email: '' 
     215 
     216        # recipes 
     217        recipes: 
     218           all: '' 
     219           specific: '' 
     220        numbers: 
     221           float: !!python/object:NeuroTools.parameters.validators.Subclass { type: !!python/name:float } 
    192222        """ 
    193223