#NEWLINE# def test_search_afilter( ) : #NEWLINE# #INDENT# import json #NEWLINE# def afilter( x ) : #NEWLINE# #INDENT# if ( x in [ 1 , 2 ] ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# dict = { #NEWLINE# #INDENT# 'a' : { #NEWLINE# #INDENT# 'view_failure' : 'a' , #NEWLINE# 'b' : { #NEWLINE# #INDENT# 'c' : { #NEWLINE# #INDENT# 'd' : 0 , #NEWLINE# 'e' : 1 , #NEWLINE# 'f' : 2 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# paths = [ 'a/b/c/e' , 'a/b/c/f' ] #NEWLINE# for ( path , value ) in dpath . util . search ( dict , '/**' , yielded = True , afilter = afilter ) : #NEWLINE# #INDENT# assert ( path in paths ) #NEWLINE# #UNINDENT# assert ( 'view_failure' not in dpath . util . search ( dict , '/**' , afilter = afilter ) [ 'a' ] ) #NEWLINE# assert ( 'd' not in dpath . util . search ( dict , '/**' , afilter = afilter ) [ 'a' ] [ 'b' ] [ 'c' ] ) #NEWLINE# for ( path , value ) in dpath . util . search ( dict , [ '**' ] , yielded = True , afilter = afilter ) : #NEWLINE# #INDENT# assert ( path in paths ) #NEWLINE# #UNINDENT# assert ( 'view_failure' not in dpath . util . search ( dict , [ '**' ] , afilter = afilter ) [ 'a' ] ) #NEWLINE# assert ( 'd' not in dpath . util . search ( dict , [ '**' ] , afilter = afilter ) [ 'a' ] [ 'b' ] [ 'c' ] )