#NEWLINE# @ mock . patch . object ( greenthread , 'spawn_after' ) #NEWLINE# def test_event_dispatch( self , mock_spawn_after ) : #NEWLINE# #INDENT# def handler( event ) : #NEWLINE# #INDENT# got_events . append ( event ) #NEWLINE# #UNINDENT# hostimpl = host . Host ( 'qemu:///system' , lifecycle_event_handler = handler ) #NEWLINE# got_events = [ ] #NEWLINE# hostimpl . _init_events_pipe ( ) #NEWLINE# event1 = event . LifecycleEvent ( 'cef19ce0-0ca2-11df-855d-b19fbce37686' , event . EVENT_LIFECYCLE_STARTED ) #NEWLINE# event2 = event . LifecycleEvent ( 'cef19ce0-0ca2-11df-855d-b19fbce37686' , event . EVENT_LIFECYCLE_PAUSED ) #NEWLINE# hostimpl . _queue_event ( event1 ) #NEWLINE# hostimpl . _queue_event ( event2 ) #NEWLINE# hostimpl . _dispatch_events ( ) #NEWLINE# want_events = [ event1 , event2 ] #NEWLINE# self . assertEqual ( want_events , got_events ) #NEWLINE# event3 = event . LifecycleEvent ( 'cef19ce0-0ca2-11df-855d-b19fbce37686' , event . EVENT_LIFECYCLE_RESUMED ) #NEWLINE# event4 = event . LifecycleEvent ( 'cef19ce0-0ca2-11df-855d-b19fbce37686' , event . EVENT_LIFECYCLE_STOPPED ) #NEWLINE# hostimpl . _queue_event ( event3 ) #NEWLINE# hostimpl . _queue_event ( handler ) #NEWLINE# hostimpl . _dispatch_events ( ) #NEWLINE# want_events = [ event1 , event2 , event3 ] #NEWLINE# self . assertEqual ( want_events , got_events ) #NEWLINE# mock_spawn_after . assert_called_once_with ( hostimpl . _lifecycle_delay , hostimpl . _event_emit , event4 )