def test_solution_fatal_compile(use_docker, solution_fatal_compile): request = ProcessRequest(src=solution_fatal_compile.read_text(), docker=use_docker, **solve_request_base) with case.assertRaises(CompileException): request.process()
def test_timeout(use_docker, solution_timeout): request = ProcessRequest(src=solution_timeout.read_text(), docker=use_docker, **solve_request_base) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT) case.assertIs(request.result['case-1.s'].status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT) case.assertGreater(request.result['case-1.s'].duration, 1.0) case.assertIs(request.result['case-2'].status, ExecutorStatus.ANSWER_CORRECT) case.assertIs(request.result['case-3.0'].status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT) case.assertIs(request.result['case-3.1'].status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT) case.assertIs(request.result['case-3.2'].status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT) case.assertIs(request.result['case-3.3'].status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT) case.assertIs(request.result['case-3.4'].status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT)
def test_wrong(use_docker, solution_wrong): request = ProcessRequest(src=solution_wrong.read_text(), docker=use_docker, **solve_request_base) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.ANSWER_WRONG) for subcase in request.iter_subcases(): result = request.result[subcase.id] case.assertIs(result.status, ExecutorStatus.ANSWER_WRONG)
def test_solution_fatal(use_docker, solution_fatal): request = ProcessRequest(src=None, docker=use_docker, **generate_input_request_base) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result.compilation.status, ExecutorStatus.OK) for subcase in request.iter_subcases(): result = request.result[subcase.id] case.assertIs(result.status, ExecutorStatus.ERROR_WHILE_RUNNING)
def test_fatal(use_docker, solution_fatal): request = ProcessRequest(src=solution_fatal.read_text(), docker=use_docker, **solve_request_base) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.ERROR_WHILE_RUNNING) for subcase in request.iter_subcases(): result = request.result[subcase.id] case.assertIs(result.status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIn('!!!FOOBAR!!!', result.stderr.read_text())
def test_solution_timeout(use_docker, solution_timeout): request = ProcessRequest(src=solution_timeout.read_text(), docker=use_docker, **solve_request_base) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT) case.assertIs(request.result.compilation.status, ExecutorStatus.OK) for subcase in request.iter_subcases(): result = request.result[subcase.id] case.assertIs(result.status, ExecutorStatus.ANSWER_CORRECT_TIMEOUT)
def test_ok(use_docker, solution_correct): request = ProcessRequest(src=None, docker=use_docker, **generate_output_request_base) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.OK) case.assertIs(request.result.compilation.status, ExecutorStatus.OK) for subcase in request.iter_subcases(): result = request.result[subcase.id] case.assertIs(result.status, ExecutorStatus.OK)
def test_solution_correct(use_docker, solution_correct): request = ProcessRequest(src=None, docker=use_docker, **generate_input_request_base) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.OK) case.assertIs(request.result['case-1.s'].status, ExecutorStatus.IGNORE) case.assertIs(request.result['case-2'].status, ExecutorStatus.OK) case.assertIs(request.result['case-3.0'].status, ExecutorStatus.OK) case.assertIs(request.result['case-3.1'].status, ExecutorStatus.OK) case.assertIs(request.result['case-3.2'].status, ExecutorStatus.OK) case.assertIs(request.result['case-3.3'].status, ExecutorStatus.OK) case.assertIs(request.result['case-3.4'].status, ExecutorStatus.OK)
def test_solution_fatal(use_docker, solution_fatal): request = ProcessRequest( src=None, docker=use_docker, **generate_output_request_base ) request.process() evaluation = request.result.result case.assertIs(evaluation.status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result['case-1.s'].status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result['case-2'].status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result['case-3.0'].status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result['case-3.1'].status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result['case-3.2'].status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result['case-3.3'].status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIs(request.result['case-3.4'].status, ExecutorStatus.ERROR_WHILE_RUNNING) case.assertIn('!!!FOOBAR!!!', request.result['case-3.4'].stderr.read_text())
def prepare_files(self, request: ProcessRequest): """ This method will copy files to a tmp dir (based on a request type) :param request: :return: """ for subcase in request.iter_subcases(): if subcase.needs_input: if subcase.problem.input.exists(): shutil.copyfile(subcase.problem.input, subcase.temp.input)
def _compile_raw(cls, request: ProcessRequest, pipeline: list, executor: LocalExecutor, out_dir: typing.Union[str, pathlib.Path]): if not pipeline: return result_id = 'compilation' request._compile_result = ExecutorResult.empty_result( result_id, ExecutorStatus.RUNNING) request.event_compile.open_event.trigger(request, request._compile_result) inn = None out = pathlib.Path(out_dir).joinpath('.compile.log') err = subprocess.STDOUT cmd = pipeline logger.opt(ansi=True).info('<red>{}</red>: {}', 'COMPILING', cmd) with executor.set_streams(stdin=inn, stdout=out, stderr=err) as ex: result = ex.run(cmd) request._compile_result = add_cmd_to_result(result_id, result).register(result_id) if result.failed(): if result.status is ExecutorStatus.GLOBAL_TIMEOUT: raise CompileException( 'Compilation was interrupted (did not finish in time)', details=result.stdout) else: result.status = ExecutorStatus.COMPILATION_FAILED raise CompileException('Compilation failed', details=result.stdout) request.event_compile.close_event.trigger(request, request._compile_result) return result
def _solve_raw(cls, request: ProcessRequest, pipeline: list, executor: LocalExecutor, in_dir, out_dir, err_dir, ref_out, teacher=False): cmd = pipeline logger.opt(ansi=True).info('<red>{}</red> - {}', 'RUNNING', cmd) for id, case, subcase in request: inn = pathlib.Path(in_dir).joinpath(subcase.id) out = pathlib.Path(out_dir).joinpath(subcase.id) err = pathlib.Path(err_dir).joinpath(subcase.id) ref = pathlib.Path(ref_out).joinpath(subcase.id) if inn.exists(): logger.opt(ansi=True).info( '{course.name}<b,g,>:</b,g,>{problem.id}<b,g,>:</b,g,>{case.id}', case=subcase, problem=request.problem, course=request.course) else: logger.opt(ansi=True).warning( '{course.name}<b,g,>:</b,g,>{problem.id}<b,g,>:</b,g,>{case.id} - ' 'input file does not exists, test will be skipped', case=subcase, problem=request.problem, course=request.course) request[id].status = ExecutorStatus.SKIPPED request[id].message = 'skipped' request[id].console = 'Input file does not exists'.splitlines() request.event_execute_test.close_event.trigger( request, request[id]) continue request[id].status = ExecutorStatus.RUNNING request.event_execute_test.open_event.trigger(request, request[id]) with executor.set_streams(stdin=inn, stdout=out, stderr=err) as ex: if teacher: result = ex.run(cmd).register(id) else: timeout = (subcase.timeout or Env.case_timeout) * request.lang.scale result = ex.run(cmd, soft_limit=timeout).register(id) # if ok we compare if result.status in (ExecutorStatus.OK, ExecutorStatus.SOFT_TIMEOUT): compare_result = Comparator.compare_files(f1=ref, f2=out) result = cls._evaluate_result(result, compare_result, subcase) request[id] = result request[id] = add_cmd_to_result(id, request[id]) request._register_attachment(id=id, name='input', path=inn) request._register_attachment(id=id, name='output', path=out) request._register_attachment(id=id, name='error', path=err) request._register_attachment(id=id, name='reference', path=ref) # request[id].add_attachment( # dict(path=inn, name='input'), # dict(path=out, name='output'), # dict(path=err, name='error'), # dict(path=ref, name='reference'), # ) request.event_execute_test.close_event.trigger( request, request[id])