| | 141 | def test_yaml_file_schema(self): |
| | 142 | import yaml, tempfile |
| | 143 | |
| | 144 | conf1_str = """ |
| | 145 | # user info |
| | 146 | username: joe |
| | 147 | email: joe@example.com |
| | 148 | |
| | 149 | # recipes |
| | 150 | recipes: |
| | 151 | all: /somewhere1/path1.xml |
| | 152 | specific: /somewhere2/path2.xml |
| | 153 | """ |
| | 154 | |
| | 155 | schema_str = """ |
| | 156 | # user info |
| | 157 | username: Subclass(type=str) |
| | 158 | email: Subclass(type=str) |
| | 159 | |
| | 160 | # recipes |
| | 161 | recipes: |
| | 162 | all: Subclass(type=str) |
| | 163 | specific: Subclass(type=str) |
| | 164 | """ |
| | 165 | |
| | 166 | def write_to_yaml_tf(s): |
| | 167 | tf = tempfile.NamedTemporaryFile(suffix='.yaml') |
| | 168 | tf.writelines(s) |
| | 169 | tf.flush() |
| | 170 | tf.seek(0) |
| | 171 | return tf |
| | 172 | |
| | 173 | schema_tf = write_to_yaml_tf(schema_str) |
| | 174 | conf1_tf = write_to_yaml_tf(conf1_str) |
| | 175 | |
| | 176 | schema = ParameterSchema(schema_tf.name) |
| | 177 | conf = ParameterSet(conf1_tf.name) |
| | 178 | |
| | 179 | v = CongruencyValidator() |
| | 180 | assert v.validate(conf,schema) |
| | 181 | |
| | 182 | del conf.recipes['all'] |
| | 183 | r = False |
| | 184 | try: |
| | 185 | r = v.validate(conf,schema) |
| | 186 | except Exception as e: |
| | 187 | assert isinstance(e,ValidationError) |
| | 188 | assert e.path=='recipes.all' |
| | 189 | assert e.parameter=='<MISSING>' |
| | 190 | assert e.schema_base==schema.recipes.all |
| | 191 | |
| | 192 | assert r == False |
| | 193 | |
| | 194 | |