test_testcases.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:schemapi 作者: altair-viz 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号