Exemplo n.º 1
0
def execute_testcases(submission_file, submission_id, problem):
    base_dir = Path(settings.MEDIA_ROOT).resolve()
    source_path = base_dir / submission_file
    testcases = TestCase.objects.filter(problem=problem)
    response = {}
    for testcase in testcases:
        testcase_path = base_dir / testcase.testcase.name
        output_path = base_dir / 'user_output' / (str(submission_id) +
                                                  str(testcase.id))
        engine = Engine(source_path=source_path,
                        testcase_path=testcase_path,
                        output_path=output_path)
        try:
            id = testcase.id
            engine.process()
        except Engine.CompileError:
            response[id] = 'error'
        except Engine.TimeOut:
            response[id] = 'TLE'
        else:
            if engine.check_output(output_path):
                response[id] = 'AC'
            else:
                response[id] = 'WA'
        current_task.update_state(state="PROGRESS", meta=response)
    return response
Exemplo n.º 2
0
def run(request):
    if request.method == 'GET':
        return render(request, 'service/run.html')
    else:
        source_code = request.FILES['source_code']
        test_case = request.FILES['test_case']
        expected_out = request.FILES['expected_out']

        source_code = save_file(source_code, '.py')
        test_case = save_file(test_case)
        expected_out = save_file(expected_out)

        output_path = Path(settings.MEDIA_ROOT) / 'tmp/' / str(uuid.uuid1())

        engine = Engine(source_path=source_code,
                        testcase_path=test_case,
                        output_path=output_path)

        try:
            engine.process()
        except:
            pass
        else:
            engine.check_output(expected_out)

        # remove(source_code)
        # remove(test_case)
        # remove(expected_out)
        # remove(output_path)

        return HttpResponse(engine.result)
Exemplo n.º 3
0
def execute(base_dir, source_path, testcase_path, output_path):
    response = ''
    engine = Engine(source_path=source_path,
                    testcase_path=testcase_path,
                    output_path=output_path)
    try:
        engine.process()
    except Engine.CompileError:
        response = 'error'
    except Engine.TimeOut:
        response = 'TLE'
    else:
        if engine.check_output(output_path):
            response = 'AC'
        else:
            response = 'WA'
    return response