def test_getter_and_setter(): value = FieldValue(field=Field()) value.set("hello") assert value.get() == "hello"
def test_optional_field_not_provided_default(): field_value = FieldValue(field=Field(optional=False)) assert field_value.is_not_provided()
def test_no_default_value(): field_value = FieldValue(field=Field()) with pytest.raises(DefaultNotProvided): field_value.get()
def test_default_value(): field_value = FieldValue(field=Field(default="hello")) assert field_value.get() == "hello"
def test_init(): field = Field() assert isinstance(field, Field)
class SimpleModel(Model): simple_field = Field(default='Hello')
def test_default_serializer(input, expected): field = Field() assert field.default_serializer(input) == expected
def test_field(): assert isinstance(Field(), Field)
def test_optional_default_not_provided(): field = Field(optional=True) assert field.get_default() == NOT_PROVIDED
def test_default_parse(): field = Field() assert field.parse("test") == "test"
def test_default_provided(): field = Field(default="test") assert field.get_default() == "test"
def test_default_not_provided(): field = Field() with pytest.raises(DefaultNotProvided): assert field.get_default() == NOT_PROVIDED
def test_cannot_be_optional_and_have_default(): with pytest.raises(InvalidFieldArguments): field = Field(optional=True, default="test")
def test_init(): field = Field() field_instance = FieldValue(field=field) assert isinstance(field_instance, FieldValue) assert field_instance.field == field
def test_raise_value_exception(): field = Field() with pytest.raises(ValueError): field._raise_value_error('test')
class TestModelMeta(metaclass=ModelMeta): TEST_ATTRIBUTE = "Hello" test_field = Field(default="World")
class SampleModel(Model): test_field_1 = Field(default="Hello") test_field_2 = Field() test_field_3 = Field(optional=True)