Skip to content

Commit

Permalink
SchemaNotProvided also needs to provide the field and value.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Aug 20, 2018
1 parent b2f99e2 commit 03d02cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/zope/schema/_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def _validate(self, value):

# schema has to be provided by value
if not self.schema.providedBy(value):
raise SchemaNotProvided
raise SchemaNotProvided(self.schema, value).with_field_and_value(self, value)

# check the value against schema
schema_error_dict = _validate_fields(self.schema, value)
Expand Down
9 changes: 8 additions & 1 deletion src/zope/schema/tests/test__field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,14 @@ def test__validate_w_value_not_providing_schema(self):
from zope.schema._bootstrapfields import Text
schema = self._makeSchema(foo=Text(), bar=Text())
objf = self._makeOne(schema)
self.assertRaises(SchemaNotProvided, objf.validate, object())
bad_value = object()
with self.assertRaises(SchemaNotProvided) as exc:
objf.validate(bad_value)

not_provided = exc.exception
self.assertIs(not_provided.field, objf)
self.assertIs(not_provided.value, bad_value)
self.assertEqual(not_provided.args, (schema, bad_value), )

def test__validate_w_value_providing_schema_but_missing_fields(self):
from zope.interface import implementer
Expand Down

0 comments on commit 03d02cf

Please sign in to comment.