#NEWLINE# def test_key( ) : #NEWLINE# #INDENT# my_dict = Datasource ( 'my_dict' ) #NEWLINE# foo = key ( 'foo' , my_dict ) #NEWLINE# eq_ ( solve ( foo , cache = { #NEWLINE# #INDENT# my_dict : { #NEWLINE# #INDENT# 'foo' : 'bar' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , 'bar' ) #NEWLINE# eq_ ( repr ( foo ) , "<datasource.my_dict['foo']>" ) #NEWLINE# bar = key ( 'bar' , my_dict , apply = or_none ( int ) ) #NEWLINE# eq_ ( solve ( bar , cache = { #NEWLINE# #INDENT# my_dict : { #NEWLINE# #INDENT# 'bar' : None , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , None ) #NEWLINE# eq_ ( solve ( bar , cache = { #NEWLINE# #INDENT# my_dict : { #NEWLINE# #INDENT# 'bar' : '1' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , 1 ) #NEWLINE# foobar = key ( [ 'foo' , 'bar' ] , my_dict ) #NEWLINE# eq_ ( solve ( bar , cache = { #NEWLINE# #INDENT# my_dict : { #NEWLINE# #INDENT# 'bar' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , None ) #NEWLINE# eq_ ( solve ( foobar , cache = { #NEWLINE# #INDENT# my_dict : { #NEWLINE# #INDENT# 'foo' : { #NEWLINE# #INDENT# 'bar' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , 1 ) #NEWLINE# eq_ ( repr ( foobar ) , "<datasource.my_dict[['foo', 'bar']]>" ) #NEWLINE# eq_ ( pickle . loads ( pickle . dumps ( foo ) ) , foo ) #NEWLINE# eq_ ( pickle . loads ( pickle . dumps ( bar ) ) , bar ) #NEWLINE# eq_ ( pickle . loads ( pickle . dumps ( foobar ) ) , foobar )