def test_execute_wrong_project_path(entrypoint, path_to_requirements): parameters = {} wrong_project_path = '/this/is/non/existing/path' exc_msg = re.escape(f"{ExecutorBuildException.PREFIX} Invalid project path directory `{wrong_project_path}` does not exist") with pytest.raises(ExecutorBuildException, match=exc_msg): with executor.execute(wrong_project_path, entrypoint, parameters, path_to_requirements) as res: print(f"ok {res}")
def test_execute_wrong_requirements(path_to_project, entrypoint): wrong_requirements_path = 'requirements_wrong.txt' exc_msg = re.escape(f"{ExecutorBuildException.PREFIX} Cannot find requirements file `{wrong_requirements_path}`") parameters = {} with pytest.raises(ExecutorBuildException, match=exc_msg): with executor.execute(path_to_project, entrypoint, parameters, wrong_requirements_path) as res: print(f"ok {res}")
def test_execute_wrong_entrypoint_file(path_to_project, path_to_requirements): wrong_entrypoint_filename = 'wrong_entrypoint.smls' # # TODO: add suggestions later: # # * "... did you provide a path to the file correctly? # # * Maybe you meant: function.py" parameters = {} exc_msg = re.escape(f"{ExecutorBuildException.PREFIX} Path to entrypoint file is not valid: " f"`{wrong_entrypoint_filename}`") with pytest.raises(ExecutorBuildException, match=exc_msg): with executor.execute(path_to_project, wrong_entrypoint_filename, parameters, path_to_requirements) as res: print(f"ok {res}")
def _trigger_job_run(job: Job, trigger_type: str, user_id: int) -> Optional[int]: job_run = JobRun(job_id=job.id, type=trigger_type) get_db_session().add(job_run) db_commit() # we need to have an id generated before we start writing logs send_update( 'status', { 'job_id': str(job.id), 'job_run_id': str(job_run.id), 'status': job_run.status }, user_id) job_entrypoint = job.entrypoint or constants.DEFAULT_ENTRYPOINT job_requirements = job.requirements or constants.DEFAULT_REQUIREMENTS path_to_job_files = storage.get_path_to_files(storage.Type.Job, job.id) try: with executor.execute(path_to_job_files, job_entrypoint, job.get_parameters_as_dict(), job_requirements, _generate_container_name(str( job.id), user_id)) as executor_result: logs, get_exit_code = executor_result.output, executor_result.get_exit_code for line in logs: _create_log_entry(line, job.id, job_run.id, user_id) exit_code = get_exit_code() except ExecutorBuildException as exc: logs, get_exit_code = (el for el in [str(exc)]), lambda: 1 for line in logs: _create_log_entry(line, job.id, job_run.id, user_id) exit_code = get_exit_code() if exit_code == 0: job_run.status = JobRunStatus.Ok.value else: job_run.status = JobRunStatus.Failed.value db_commit() send_update( 'status', { 'job_id': str(job.id), 'job_run_id': str(job_run.id), 'status': job_run.status }, user_id) return exit_code
def test_legacy_entrypoint(path_to_project, path_to_requirements): legacy_entrypoint = 'function.main' parameters = {} with executor.execute(path_to_project, legacy_entrypoint, parameters, path_to_requirements) as res: assert "List of news media APIs" in ''.join(list(res.output)) assert res.get_exit_code() == 0
def test_execute_project_with_error(path_to_project, entrypoint_to_corrupted_program, path_to_requirements): parameters = {} with executor.execute(path_to_project, entrypoint_to_corrupted_program, parameters, path_to_requirements) as res: assert "Traceback" in ''.join(res.output) assert res.get_exit_code() == 1
def test_execute_succesfull_return_value(path_to_project, path_to_requirements, entrypoint): # we are reading from https://en.wikipedia.org/wiki/List_of_news_media_APIs parameters = {} with executor.execute(path_to_project, entrypoint, parameters, path_to_requirements) as res: return_value_from_function = "Everything is alright" assert return_value_from_function in ''.join(res.output)
def test_execute_succesfull(path_to_project, path_to_requirements, entrypoint): # we are reading from https://en.wikipedia.org/wiki/List_of_news_media_APIs parameters = {} with executor.execute(path_to_project, entrypoint, parameters, path_to_requirements) as res: assert "List of news media APIs" in ''.join(list(res.output)) assert res.get_exit_code() == 0