halst/schema — pull request #18 by Rogdham (2013-05-13 19:40:26+00:00)
Title: Handle wrong keys better. Fixes #3 and #15

This PR fixes problems for wrong keys (see 2 bugs reports).

I simply removed a case which is always handle afterwards.

More precisely, if a key is missing, instead of sometimes stopping there and sometimes reporting the set of missing mandatory keys, now it always reports the set of mandatory keys.

>>> Schema({'foo': str, 'bar': str}).validate({'foo': 'blah'})
Traceback (most recent call last):
…
schema.SchemaError: missed keys set(['bar'])
>>> Schema({'bar': str}).validate({'foo': 'blah'}) # I fixed unit test for that one
Traceback (most recent call last):
…
schema.SchemaError: missed keys set(['bar'])

The only case where it stops before for “missing” keys is when in fact the key was present but failed internally; I changed the error message in that case to be clearer.

>>> Schema({'foo': str}).validate({'foo': 42})
Traceback (most recent call last):
…
schema.SchemaError: invalid value for key 'foo'
42 should be instance of