#NEWLINE# def test_each_validator( self ) : #NEWLINE# #INDENT# passes = { #NEWLINE# #INDENT# 'foo' : [ 1 , 2 , 3 , 4 , 5 , 6 ] , #NEWLINE# 'bar' : [ { #NEWLINE# #INDENT# 'qux' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'qux' : 2 , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# fails = { #NEWLINE# #INDENT# 'foo' : [ 1 , 2 , 3 , 4 , 5 , 11 ] , #NEWLINE# 'bar' : [ { #NEWLINE# #INDENT# 'qux' : 3 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'qux' : 4 , #NEWLINE# 'zot' : 5 , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# validation = { #NEWLINE# #INDENT# 'foo' : [ Required , Each ( [ Range ( 0 , 10 ) ] ) ] , #NEWLINE# 'bar' : [ Required , Each ( { #NEWLINE# #INDENT# 'qux' : [ Required , Range ( 0 , 2 ) ] , #NEWLINE# 'zot' : [ In ( [ 1 , 2 , 3 ] ) ] , #NEWLINE# #UNINDENT# } ) ] , #NEWLINE# #UNINDENT# } #NEWLINE# ( valid , errors ) = validate ( validation , passes ) #NEWLINE# assert valid #NEWLINE# assert ( len ( errors ) == 0 ) #NEWLINE# ( valid , errors ) = validate ( validation , fails ) #NEWLINE# assert ( not valid ) #NEWLINE# assert ( len ( validation ) == 2 ) #NEWLINE# assert ( errors == { #NEWLINE# #INDENT# 'foo' : [ 'all values must fall between 0 and 10' ] , #NEWLINE# 'bar' : [ { #NEWLINE# #INDENT# 0 : { #NEWLINE# #INDENT# 'qux' : [ 'must fall between 0 and 2' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# 1 : { #NEWLINE# #INDENT# 'qux' : [ 'must fall between 0 and 2' ] , #NEWLINE# 'zot' : [ 'must be one of [1, 2, 3]' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } )