Exemple #1
0
    def Submit(self, ui, solution):
        if not solution.project.atcoder_config_defined:
            ui.errors.Error(solution,
                            'atcoder_config() is not defined in PROJECT.')
            yield False

        solution.project._Login()

        task_id = str(solution.problem.atcoder_task_id)
        lang_id = solution.project.atcoder_lang_ids[solution.code.PREFIX]
        source_code = files.ReadFile(
            os.path.join(solution.src_dir, solution.code.src_name))

        ui.console.PrintAction('SUBMIT',
                               solution,
                               str({
                                   'task_id': task_id,
                                   'lang_id': lang_id
                               }),
                               progress=True)

        html = solution.project._Request('submit?task_id=%s' % task_id).read()
        pat = re.compile(r'name="__session" value="([^"]+)"')
        m = pat.search(str(html))
        session = m.group(1)
        r = solution.project._Request(
            'submit?task_id=%s' % task_id, {
                '__session': session,
                'task_id': task_id,
                'language_id_' + task_id: lang_id,
                'source_code': source_code
            })
        r.read()

        results = solution.project._Request('submissions/me').read()
        submit_id = str(results).split('<td><a href="/submissions/')[1].split(
            '"')[0]

        ui.console.PrintAction('SUBMIT',
                               solution,
                               'submitted: ' + str(submit_id),
                               progress=True)

        while True:
            result, progress = str(
                solution.project._Request('submissions/' +
                                          submit_id).read()).split(
                                              'data-title="')[1].split('"', 1)
            if 'Judging' not in result:
                break
            time.sleep(5.0)

        if solution.IsCorrect():
            expected = ''
        else:
            expected = '(fake solution)'
        ui.console.PrintAction('SUBMIT', solution,
                               '{0} {1}'.format(result, expected))

        yield True
Exemple #2
0
    def _TestSolutionWithAllCases(self, solution, ui):
        """Test a solution without challenge cases.

        The solution can be marked as wrong but without challenge cases.
        """
        testcases = self.ListTestCases()
        result = test.TestsetResult(self, solution, testcases)
        # Try all cases.
        yield taskgraph.TaskBranch([
            self._TestSolutionWithAllCasesOne(solution, testcase, result, ui)
            for testcase in testcases
        ],
                                   unsafe_interrupt=True)
        if not result.IsFinalized():
            if solution.IsCorrect():
                result.Finalize(True, result.GetTimeStats(ui))
            else:
                result.Finalize(False, 'Unexpectedly accepted all test cases')
                ui.errors.Error(solution, result.detail)
        yield result
Exemple #3
0
    def _TestSolutionWithAllCasesOne(self, solution, testcase, result, ui):
        """Test a solution without challenge cases.

        The solution can be marked as wrong but without challenge cases.
        """
        case_result = yield self._TestOneCase(solution, testcase, ui)
        result.results[testcase] = case_result
        if case_result.verdict not in (test.TestCaseResult.AC,
                                       test.TestCaseResult.WA,
                                       test.TestCaseResult.TLE,
                                       test.TestCaseResult.RE):
            result.Finalize(False,
                            '%s: Judge Error' %
                            os.path.basename(testcase.infile),
                            notable_testcase=testcase)
            ui.errors.Error(solution, result.detail)
            if ui.options.keep_going:
                yield False
            else:
                raise taskgraph.Bailout([False])
        elif case_result.verdict != test.TestCaseResult.AC:
            expected = not solution.IsCorrect()
            r = test.TestsetResult(result.testset, result.solution,
                                   result.testcases)
            r.Finalize(
                expected,
                '%s: %s' %
                (os.path.basename(testcase.infile), case_result.verdict),
                notable_testcase=testcase)
            result.Finalize(
                expected,
                '%s: %s' %
                (os.path.basename(testcase.infile), case_result.verdict),
                notable_testcase=testcase)
            if solution.IsCorrect():
                if case_result.verdict == test.TestCaseResult.WA:
                    judgefile = os.path.join(
                        solution.out_dir,
                        os.path.splitext(os.path.basename(testcase.infile))[0]
                        + consts.JUDGE_EXT)
                    ui.errors.Error(
                        solution,
                        '%s\n  judge log: %s' % (r.detail, judgefile))
                else:
                    ui.errors.Error(solution, r.detail)
            elif (solution.expected_verdicts is not None
                  and case_result.verdict not in solution.expected_verdicts):
                r = test.TestsetResult(result.testset, result.solution,
                                       result.testcases)
                r.Finalize(
                    False,
                    '%s: Unexpected Verdict (%s)' %
                    (os.path.basename(testcase.infile), case_result.verdict),
                    notable_testcase=testcase)
                ui.errors.Error(solution, r.detail)
                if case_result.verdict == test.TestCaseResult.WA:
                    judgefile = os.path.join(
                        solution.out_dir,
                        os.path.splitext(os.path.basename(testcase.infile))[0]
                        + consts.JUDGE_EXT)
                    ui.errors.Error(
                        solution,
                        '%s\n  judge log: %s' % (r.detail, judgefile))
                else:
                    ui.errors.Error(solution, r.detail)
            if ui.options.keep_going:
                yield False
            else:
                raise taskgraph.Bailout([False])
        ui.console.PrintAction('TEST',
                               solution,
                               '%s: PASSED' %
                               os.path.basename(testcase.infile),
                               progress=True)
        yield True