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")
评论列表
文章目录