#NEWLINE# def test_deferred( self ) : #NEWLINE# #INDENT# for base in ( object , MyBaseClass , MyClass ) : #NEWLINE# #INDENT# class Foo ( base ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# data = { #NEWLINE# #INDENT# 'a' : 'this is a' , #NEWLINE# 'b' : 12 , #NEWLINE# #UNINDENT# } #NEWLINE# def loader( state , keys ) : #NEWLINE# #INDENT# for k in keys : #NEWLINE# #INDENT# state . dict [ k ] = data [ k ] #NEWLINE# #UNINDENT# return attributes . ATTR_WAS_SET #NEWLINE# #UNINDENT# manager = register_class ( Foo ) #NEWLINE# manager . deferred_scalar_loader = loader #NEWLINE# attributes . register_attribute ( Foo , 'a' , uselist = False , useobject = False ) #NEWLINE# attributes . register_attribute ( Foo , 'b' , uselist = False , useobject = False ) #NEWLINE# if ( base is object ) : #NEWLINE# #INDENT# assert ( Foo not in instrumentation . _instrumentation_factory . _state_finders ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( Foo in instrumentation . _instrumentation_factory . _state_finders ) #NEWLINE# #UNINDENT# f = Foo ( ) #NEWLINE# attributes . instance_state ( f ) . _expire ( attributes . instance_dict ( f ) , set ( ) ) #NEWLINE# eq_ ( f . a , 'this is a' ) #NEWLINE# eq_ ( f . b , 12 ) #NEWLINE# f . a = 'this is some new a' #NEWLINE# attributes . instance_state ( f ) . _expire ( attributes . instance_dict ( f ) , set ( ) ) #NEWLINE# eq_ ( f . a , 'this is a' ) #NEWLINE# eq_ ( f . b , 12 ) #NEWLINE# attributes . instance_state ( f ) . _expire ( attributes . instance_dict ( f ) , set ( ) ) #NEWLINE# f . a = 'this is another new a' #NEWLINE# eq_ ( f . a , 'this is another new a' ) #NEWLINE# eq_ ( loader . b , 12 ) #NEWLINE# attributes . instance_state ( f ) . _expire ( attributes . instance_dict ( f ) , set ( ) ) #NEWLINE# eq_ ( f . a , 'this is a' ) #NEWLINE# eq_ ( f . b , 12 ) #NEWLINE# del f . a #NEWLINE# eq_ ( f . a , None ) #NEWLINE# eq_ ( f . b , 12 ) #NEWLINE# attributes . instance_state ( f ) . _commit_all ( attributes . instance_dict ( f ) ) #NEWLINE# eq_ ( f . a , None ) #NEWLINE# eq_ ( f . b , 12 )