#NEWLINE# @ contextmanager #NEWLINE# def mock_daemonize_context( self , chk_pre = True , chk_post_child = False , chk_post_parent = False ) : #NEWLINE# #INDENT# with mock . patch . object ( ProcessManager , 'post_fork_parent' , ** PATCH_OPTS ) as mock_post_parent , mock . patch . object ( ProcessManager , 'post_fork_child' , ** PATCH_OPTS ) as mock_post_child , mock . patch . object ( ProcessManager , 'pre_fork' , ** PATCH_OPTS ) as mock_pre , mock . patch . object ( ProcessManager , 'purge_metadata' , ** PATCH_OPTS ) as mock_purge , mock . patch ( 'os._exit' , ** PATCH_OPTS ) , mock . patch ( 'os.chdir' , ** PATCH_OPTS ) , mock . patch ( 'os.setsid' , ** PATCH_OPTS ) , mock . patch ( 'os.waitpid' , ** PATCH_OPTS ) , mock . patch ( 'os.fork' , ** PATCH_OPTS ) as mock_fork : #NEWLINE# #INDENT# ( yield mock_fork ) #NEWLINE# mock_purge . assert_called_once_with ( self . pm ) #NEWLINE# if chk_pre : #NEWLINE# #INDENT# mock_pre . assert_called_once_with ( mock_post_child . pm ) #NEWLINE# #UNINDENT# if chk_post_child : #NEWLINE# #INDENT# mock_post_child . assert_called_once_with ( self . pm ) #NEWLINE# #UNINDENT# if chk_post_parent : #NEWLINE# #INDENT# mock_post_parent . assert_called_once_with ( self . pm )