def test_testcases_traitlets(testcase):
testcase = testcases[testcase]
modulename = '_schema'
schema = testcase['schema']
valid = testcase.get('valid', [])
invalid = testcase.get('invalid', [])
traitlets_obj = JSONSchema(schema)
for key, code in traitlets_obj.source_tree().items():
if key in ['jstraitlets.py', 'tests']:
continue
# Print code here... useful for debugging when errors happen
print(70 * '#')
print(code)
print()
schema = traitlets_obj.load_module(modulename, reload_module=True)
for instance in valid:
schema.Root.from_dict(instance)
for instance in invalid:
with pytest.raises(T.TraitError):
r = schema.Root.from_dict(instance)
r.to_dict() # catches unfilled requirements
评论列表
文章目录