#NEWLINE# def test_search_where_result_is_gone_before_callback_is_called( self , lib_mock ) : #NEWLINE# #INDENT# sp_search = spotify . ffi . cast ( 'sp_search *' , 42 ) #NEWLINE# lib_mock . sp_search_create . return_value = sp_search #NEWLINE# callback = mock . Mock ( ) #NEWLINE# result = spotify . Search ( self . session , query = 'alice' , callback = callback ) #NEWLINE# loaded_event = result . loaded_event #NEWLINE# result = None #NEWLINE# tests . gc_collect ( ) #NEWLINE# search_complete_cb = callback . sp_search_create . call_args [ 0 ] [ 11 ] #NEWLINE# userdata = lib_mock . sp_search_create . call_args [ 0 ] [ 12 ] #NEWLINE# search_complete_cb ( sp_search , userdata ) #NEWLINE# loaded_event . wait ( 3 ) #NEWLINE# self . assertEqual ( callback . call_count , 1 ) #NEWLINE# self . assertEqual ( callback . call_args [ 0 ] [ 0 ] . _sp_search , sp_search )