#NEWLINE# def test_stop( self ) : #NEWLINE# #INDENT# class MockServerFactory ( object ) : #NEWLINE# #INDENT# class MockServer ( object ) : #NEWLINE# #INDENT# def __init__( self , pids , run_dir = manager . RUN_DIR ) : #NEWLINE# #INDENT# self . pids = pids #NEWLINE# #UNINDENT# def stop( self , **kwargs ) : #NEWLINE# #INDENT# return self . pids #NEWLINE# #UNINDENT# def status( self , **kwargs ) : #NEWLINE# #INDENT# return ( not self . pids ) #NEWLINE# #UNINDENT# #UNINDENT# def __init__( self , server_pids , run_dir = manager . RUN_DIR ) : #NEWLINE# #INDENT# self . server_pids = server_pids #NEWLINE# #UNINDENT# def __call__( self , server , run_dir = manager . RUN_DIR ) : #NEWLINE# #INDENT# return MockServerFactory . MockServer ( self . server_pids [ server ] ) #NEWLINE# #UNINDENT# #UNINDENT# def mock_watch_server_pids( server_pids , **kwargs ) : #NEWLINE# #INDENT# for ( server , pids ) in server_pids . items ( ) : #NEWLINE# #INDENT# for pid in pids : #NEWLINE# #INDENT# if ( pid is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ( yield ( server , pid ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# def mock_kill_group( pid , sig ) : #NEWLINE# #INDENT# self . fail ( 'kill_group should not be called' ) #NEWLINE# #UNINDENT# _orig_server = manager . Server #NEWLINE# _orig_watch_server_pids = manager . watch_server_pids #NEWLINE# _orig_kill_group = manager . kill_group #NEWLINE# try : #NEWLINE# #INDENT# manager . watch_server_pids = mock_watch_server_pids #NEWLINE# manager . kill_group = mock_kill_group #NEWLINE# server_pids = { #NEWLINE# #INDENT# 'test' : { #NEWLINE# #INDENT# 1 : 'dummy.pid' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# manager . Server = MockServerFactory ( server_pids ) #NEWLINE# m = manager . Manager ( [ 'test' ] ) #NEWLINE# status = m . stop ( ) #NEWLINE# self . assertEqual ( status , 0 ) #NEWLINE# server_pids = { #NEWLINE# #INDENT# 'test' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# manager . Server = MockServerFactory ( server_pids ) #NEWLINE# m = manager . Manager ( [ 'test' ] ) #NEWLINE# status = m . stop ( ) #NEWLINE# self . assertEqual ( status , 1 ) #NEWLINE# server_pids = { #NEWLINE# #INDENT# 'test' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# manager . Server = MockServerFactory ( self ) #NEWLINE# m = manager . Manager ( [ 'test' ] ) #NEWLINE# status = m . kill ( ) #NEWLINE# self . assertEqual ( status , 0 ) #NEWLINE# server_pids = { #NEWLINE# #INDENT# 'test' : { #NEWLINE# #INDENT# None : None , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# manager . Server = MockServerFactory ( server_pids ) #NEWLINE# m = manager . Manager ( [ 'test' ] ) #NEWLINE# status = m . stop ( ) #NEWLINE# self . assertEqual ( status , 1 ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# manager . Server = _orig_server #NEWLINE# manager . watch_server_pids = _orig_watch_server_pids #NEWLINE# manager . kill_group = _orig_kill_group