#NEWLINE# def test_receive_changes( self ) : #NEWLINE# #INDENT# 'test that Listeners can mutate the given value.' #NEWLINE# class Foo ( object ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# class Bar ( object ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# def append( state , child , initiator ) : #NEWLINE# #INDENT# b2 = Bar ( ) #NEWLINE# b2 . data = ( b1 . data + ' appended' ) #NEWLINE# return b2 #NEWLINE# #UNINDENT# def on_set( state , value , oldvalue , initiator ) : #NEWLINE# #INDENT# return ( value + ' modified' ) #NEWLINE# #UNINDENT# instrumentation . register_class ( Foo ) #NEWLINE# instrumentation . register_class ( Bar ) #NEWLINE# attributes . register_attribute ( Foo , 'data' , uselist = False , useobject = False ) #NEWLINE# attributes . register_attribute ( Foo , 'barlist' , uselist = True , useobject = True ) #NEWLINE# attributes . register_attribute ( Foo , 'barset' , typecallable = set , uselist = True , useobject = True ) #NEWLINE# attributes . register_attribute ( Bar , 'data' , uselist = False , useobject = False ) #NEWLINE# event . listen ( Foo . data , 'set' , on_set , retval = True ) #NEWLINE# event . listen ( Foo . barlist , 'append' , append , retval = True ) #NEWLINE# event . listen ( Foo . barset , 'append' , append , retval = True ) #NEWLINE# f1 = Foo ( ) #NEWLINE# f1 . data = 'some data' #NEWLINE# eq_ ( f1 . data , 'some data modified' ) #NEWLINE# b1 = Bar ( ) #NEWLINE# b1 . data = 'some bar' #NEWLINE# f1 . barlist . append ( b1 ) #NEWLINE# assert ( b1 . data == 'some bar' ) #NEWLINE# assert ( f1 . barlist [ 0 ] . data == 'some bar appended' ) #NEWLINE# f1 . barset . add ( b1 ) #NEWLINE# assert ( f1 . barset . pop ( ) . data == 'some bar appended' )