def test_base_listener_redirects_exception_message_when_worker_sends_exception(): exception_message = "Here is the mock exception message" def mock_request(*args, **kwargs): raise Exception(exception_message) def mock_mark_ready(): pass served_requests = { "/mock_request": mock_request } process = Process(target=lambda: listener_server.start_listening(served_requests, multithreaded=False, mark_as_ready_callback=mock_mark_ready)) process.start() return_code = req.get("http://localhost:8000/mock_request") assert exception_message in return_code.text print("Return code", return_code) process.terminate() process.join()
def test_base_listener_sends_code_500_when_worker_sends_exception(): def mock_request(*args, **kwargs): raise Exception("Mock exception") def mock_mark_ready(): pass served_requests = { "/mock_request": mock_request } process = Process(target=lambda: listener_server.start_listening(served_requests, multithreaded=False, mark_as_ready_callback=mock_mark_ready)) process.start() return_code = req.get("http://localhost:8000/mock_request") print(return_code.text) assert return_code.status_code == 500 print("Return code", return_code) process.terminate() process.join()
result_dict = {} lungmask_dir = "lungmask_output" os.makedirs(os.path.join(data_share, lungmask_dir), exist_ok=True) unique_id = cutils.get_unique_id() hostname = os.environ["LUNGMASK_HOSTNAME"] rel_seg_save_path = os.path.join( lungmask_dir, f"{hostname}-segmentation-{unique_id}.nii.gz") abs_seg_save_path = os.path.join(data_share, rel_seg_save_path) segmentation_nifti = sitk.GetImageFromArray(segmentation) segmentation_nifti.SetSpacing(input_image.GetSpacing()) sitk.WriteImage(segmentation_nifti, abs_seg_save_path) result_dict["segmentation"] = rel_seg_save_path return result_dict, True if __name__ == "__main__": setup_logging() log_info("Started listening") served_requests = {"/lungmask_segment": run_lungmask} listener_server.start_listening(served_requests, multithreaded=True, mark_as_ready_callback=mark_yourself_ready)