Skip to content

Instantly share code, notes, and snippets.

@awagner83
Created March 27, 2012 13:22
Show Gist options
  • Save awagner83/2215825 to your computer and use it in GitHub Desktop.
Save awagner83/2215825 to your computer and use it in GitHub Desktop.
Recursive data-structure validation with datatype-0.9a3
from datatype.validation import is_valid, failures
from datatype import named, reference
# note the new
datatype = named('child', {'a': 'str', 'optional b': reference('child')})
# valid
assert is_valid(datatype, {'a': 'some', 'b': {'a': 'foo'}})
assert is_valid(datatype,
{'a': 'foo', 'b': {'a': 'bar', 'b': {'a': 'baz'}}})
# invalid
assert not is_valid(datatype, {'b': {'a': 'foobar'}})
print failures(datatype, {'b': {'a': 'foobar'}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment