class Dummy(mapping.Mapping): foo = mapping.Field(default='bar') bar = mapping.ComponentField(mapping=mapping.Component.build( mapping.IntegerField(name='a'), mapping.IntegerField(name='b'), mapping.IntegerField(name='c'), ), default=[1, 2, 3])
class Dummy(mapping.Mapping): field = mapping.Field(length=10)
class Dummy(mapping.Mapping): field = mapping.Field(required=True)
class Dummy(mapping.Mapping): field = mapping.ComponentField(mapping=mapping.Component.build( mapping.Field(name='foo'), mapping.IntegerField(name='bar'), mapping.ConstantField(name='baz', default='42')))
class Dummy(mapping.Mapping): field = mapping.Field(default=lambda: 'foobar')
def test_init_with_custom_default_value(self): f = mapping.Field(default='foo') self.assertEqual(f.default, 'foo')
def test_init_with_custom_name(self): f = mapping.Field(name='foo') self.assertEqual(f.name, 'foo')
def test_init_default(self): f = mapping.Field() self.assertTrue(hasattr(f, 'name')) self.assertTrue(hasattr(f, 'default')) self.assertEqual(f.name, None) self.assertEqual(f.default, None)