def test___new___subclassed_basic(self): # When extending a Model the parent field attributes should also be # present. class Example(Model): a = fields.Int() b = fields.Bool() class Example2(Example): pass assert Example2.__fields__.a == fields.Int() assert Example2.__fields__.b == fields.Bool()
def test___new___annotations_basic(self): # Check that basic annotations can be used. class Example(Model): a: fields.Int() b: fields.Bool() # The field attributes should not be present on the final class. assert not hasattr(Example, 'a') assert not hasattr(Example, 'b') # But they should be in the `__fields__` attribute assert Example.__fields__.a == fields.Int() assert Example.__fields__.b == fields.Bool()
def test___new___basic(self): # Check that the ModelType basic usage works, Fields should be pulled # off the class and added as a `__fields__` attribute. class Example(Model): a = fields.Int() b = fields.Bool() # The field attributes should not be present on the final class. assert not hasattr(Example, 'a') assert not hasattr(Example, 'b') # But they should be in the `__fields__` attribute assert Example.__fields__.a == fields.Int() assert Example.__fields__.b == fields.Bool()
class Example(Model): a: fields.Int() b: fields.Bool()
class Example(Model): a: int b = fields.Bool()
class Game(Model): finished = fields.Bool() players = fields.List(Player) board = fields.Dict(str, int)
class Example(Model): a = fields.Int() b = fields.Bool() c = fields.Str()