test_jstraitlets.py 文件源码

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

项目:schemapi 作者: altair-viz 项目源码 文件源码
def test_hastraits_required():

    class Foo(jst.JSONHasTraits):
        _required_traits = ['name']
        name = jst.JSONString()
        age = jst.JSONNumber()

    f1 = Foo(name="Sue", age=32)
    f2 = Foo(age=32)

    # contains all required pieces
    f1.to_dict()

    with pytest.raises(T.TraitError) as err:
        f2.to_dict()
    assert err.match("Required trait 'name' is undefined")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号