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

Added another test case of using yaml to define the schema

Files:
1 modified

Legend:

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

    r456 r457  
    9292            assert e.parameter==ps3.ps2.ps.a 
    9393            assert e.schema_base==s1.ps2.ps.a 
    94         assert r==False 
     94        assert r == False 
     95 
     96 
     97    def test_yaml_schema(self): 
     98        import yaml 
     99 
     100        conf1_str = """ 
     101        # user info 
     102        username: joe 
     103        email:  joe@example.com 
     104 
     105        # recipes 
     106        recipes: 
     107           all: /somewhere1/path1.xml 
     108           specific: /somewhere2/path2.xml 
     109        """ 
     110 
     111        schema_str = """ 
     112        # user info 
     113        username: Subclass(type=str) 
     114        email:  Subclass(type=str) 
     115 
     116        # recipes 
     117        recipes: 
     118           all: Subclass(type=str) 
     119           specific: Subclass(type=str) 
     120        """ 
     121 
     122        schema = ParameterSchema(yaml.load(schema_str)) 
     123        conf = ParameterSet(yaml.load(conf1_str)) 
     124 
     125        v = CongruencyValidator() 
     126        assert v.validate(conf,schema) 
     127 
     128        del conf.recipes['all'] 
     129        r = False 
     130        try: 
     131            r = v.validate(conf,schema) 
     132        except Exception as e: 
     133            assert isinstance(e,ValidationError) 
     134            assert e.path=='recipes.all' 
     135            assert e.parameter=='<MISSING>' 
     136            assert e.schema_base==schema.recipes.all 
     137 
     138        assert r == False 
     139 
    95140 
    96141    def test_congruent_dicts(self):