Created
March 27, 2012 13:22
-
-
Save awagner83/2215825 to your computer and use it in GitHub Desktop.
Recursive data-structure validation with datatype-0.9a3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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