def test_validate_not_field(self): schema = Schema() schema.lst = ListField(int) config = schema() proxy = ListProxy(config, schema.lst) with pytest.raises(TypeError): proxy._validate(10)
def test_validate_schema_invalid(self): schema = Schema() schema.x = IntField(default=1) schema.y = IntField(default=2) cfg = MockConfig() proxy = ListProxy(cfg, schema) with pytest.raises(ValueError): proxy._validate(100)
def test_validate_item_validation_error(self): schema = Schema() field = IntField() list_field = schema.x = ListField(field) config = schema() proxy = ListProxy(config, list_field) orig_exc = ValidationError(config, list_field, ValueError('asdf')) with patch.object(field, 'validate') as mock_validate: mock_validate.side_effect = orig_exc with pytest.raises(ValueError): proxy._validate(2)
def test_validate_item_valid(self): schema = Schema() field = IntField() list_field = schema.x = ListField(field) config = schema() proxy = ListProxy(config, list_field) with patch.object(field, 'validate') as mock_validate: retval = mock_validate.return_value = object() assert proxy._validate(2) is retval mock_validate.assert_called_once_with(config, 2)
def test_validate_schema_dict(self): schema = Schema() schema.x = IntField(default=1) schema.y = IntField(default=2) cfg = MockConfig() proxy = ListProxy(cfg, ListField(schema)) check = proxy._validate({'x': 10}) assert isinstance(check, Config) assert check.x == 10 assert check.y == 2 assert check._parent is cfg assert check._schema is schema
def test_validate_schema_config(self): schema = Schema() schema.x = IntField(default=1) schema.y = IntField(default=2) cfg = MockConfig() proxy = ListProxy(cfg, ListField(schema)) val = schema() val.x = 10 check = proxy._validate(val) assert isinstance(check, Config) assert check is val assert check._parent is cfg assert check._schema is schema