示例#1
0
文件: testset.py 项目: okaduki/rime
 def _RunGenerators(self, ui):
     """Run all input generators."""
     results = yield taskgraph.TaskBranch([
         self._RunGeneratorOne(generator, ui)
         for generator in self.generators
     ])
     yield all(results)
示例#2
0
    def _PostBuildHook(self, ui):
        if not (yield super(Testset, self)._PostBuildHook(ui)):
            yield False
        if not all((yield taskgraph.TaskBranch([
                self._GenerateMergedTest(testcase, ui)
                for testcase in self.GetMergedTestCases()
        ]))):
            yield False

        if not all((yield taskgraph.TaskBranch([
                self._ValidateMergedTest(testcase, ui)
                for testcase in self.GetMergedTestCases()
        ]))):
            yield False

        yield True
示例#3
0
文件: testset.py 项目: okaduki/rime
 def _CompileValidators(self, ui):
     """Compile input validators."""
     results = yield taskgraph.TaskBranch([
         self._CompileValidatorOne(validator, ui)
         for validator in self.validators
     ])
     yield all(results)
示例#4
0
文件: testset.py 项目: okaduki/rime
 def Test(self, ui):
     """Run tests in the testset."""
     results = yield taskgraph.TaskBranch([
         self.TestSolution(solution, ui)
         for solution in self.problem.solutions
     ])
     yield list(itertools.chain(*results))
示例#5
0
    def _TestSolutionWithChallengeCases(self, solution, ui):
        """Test a wrong solution which has specified challenge cases."""
        all_testcases = self.ListTestCases()
        challenge_infiles = solution.challenge_cases
        testcases = []
        for infile in challenge_infiles:
            matched_testcases = [
                testcase for testcase in all_testcases
                if fnmatch.fnmatch(os.path.basename(testcase.infile), infile)
            ]

            if not matched_testcases:
                ui.errors.Error(solution,
                                'Challenge case not found: %s' % infile)
                result = test.TestsetResult(self, solution, [])
                result.Finalize(False, 'Challenge case not found: %s' % infile)
                yield result

            testcases.extend(
                [t for t in matched_testcases if t.infile not in testcases])
        # Try challenge cases.
        result = test.TestsetResult(self, solution, testcases)
        yield taskgraph.TaskBranch([
            self._TestSolutionWithChallengeCasesOne(
                solution, testcase, result, ui) for testcase in testcases
        ],
                                   unsafe_interrupt=True)
        if not result.IsFinalized():
            result.Finalize(False, 'Unexpectedly accepted all challenge cases')
            ui.errors.Error(solution, result.detail)
        yield result
示例#6
0
文件: testset.py 项目: okaduki/rime
 def Build(self, ui):
     """Build testset."""
     if self.IsBuildCached():
         if not self.ListTestCases():
             ui.errors.Warning(self, 'No test case found')
         yield True
     if not (yield self._InitOutputDir(ui)):
         yield False
     if not all((yield taskgraph.TaskBranch([
             self._CompileGenerators(ui),
             self._CompileValidators(ui),
             self._CompileJudges(ui)
     ]))):
         yield False
     if not (yield self._RunGenerators(ui)):
         yield False
     if not (yield self._RunValidators(ui)):
         yield False
     if not self.ListTestCases():
         ui.errors.Warning(self, 'No test case found')
     else:
         if not (yield self._CompileReferenceSolution(ui)):
             yield False
         if not (yield self._RunReferenceSolution(ui)):
             yield False
     if not (yield self._PostBuildHook(ui)):
         yield False
     if not self.SetCacheStamp(ui):
         yield False
     yield True
示例#7
0
    def _CompileJudges(self, ui):
        res = (yield super(Testset, self)._CompileJudges(ui))
        if not res:
            yield False

        results = yield taskgraph.TaskBranch([
            self._CompileReactiveOne(reactive, ui)
            for reactive in self.reactives
        ])
        yield all(results)
示例#8
0
 def Upload(self, ui):
     if not (yield self.Pack(ui)):
         yield False
     if len(uploader_registry.classes) > 0:
         results = yield taskgraph.TaskBranch(
             [uploader().Upload(ui, self, not ui.options.upload)
              for uploader in uploader_registry.classes.values()])
         yield all(results)
     else:
         ui.errors.Error(self, "Upload nothing: you must add some plugin.")
         yield False
示例#9
0
 def Pack(self, ui):
     if not (yield self.Build(ui)):
         yield False
     if len(packer_registry.classes) > 0:
         results = yield taskgraph.TaskBranch(
             [packer().Pack(ui, self) for packer
              in packer_registry.classes.values()])
         yield all(results)
     else:
         ui.errors.Error(self, "Pack nothing: you must add some plugin.")
         yield False
示例#10
0
 def Submit(self, ui):
     if not (yield self.Build(ui)):
         yield False
     if len(submitter_registry.classes) > 0:
         results = yield taskgraph.TaskBranch(
             [submitter().Submit(ui, self) for submitter
              in submitter_registry.classes.values()])
         yield all(results)
     else:
         ui.errors.Error(self, "Submit nothing: you must add some plugin.")
         yield False
示例#11
0
 def _TestSolutionWithMergedTests(self, solution, ui):
   testcases = self.GetMergedTestCases()
   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():
     result.Finalize(True, 'okay')
   yield result
示例#12
0
 def _ValidateMergedTest(self, merged_testcase, ui):
     if not self.validators:
         if self.base_dir:
             ui.errors.Warning(self, 'Validator unavailable')
         yield True
     testcases = self.GetMergedTestCases()
     results = yield taskgraph.TaskBranch([
         self._RunValidatorOne(validator, testcase, ui)
         for validator in self.validators for testcase in testcases
     ])
     if not all(results):
         yield False
     ui.console.PrintAction('VALIDATE', self, 'OK Merged Cases')
     yield True
示例#13
0
 def _RunValidators(self, ui):
     """Run input validators."""
     if not self.validators:
         # Ignore when this testset actually does not exist.
         if self.base_dir:
             ui.errors.Warning(self, 'Validator unavailable')
         yield True
     testcases = self.ListTestCases()
     results = yield taskgraph.TaskBranch([
         self._RunValidatorOne(validator, testcase, ui)
         for validator in self.validators for testcase in testcases
     ])
     if not all(results):
         yield False
     invalidcases = self.ListInvalidTestCases()
     results = yield taskgraph.TaskBranch([
         self._RunValidatorForInvalidCasesOne(validator, invalidcase, ui)
         for validator in self.validators for invalidcase in invalidcases
     ])
     if not all(results):
         yield False
     ui.console.PrintAction('VALIDATE', self, 'OK')
     yield True
示例#14
0
文件: testset.py 项目: okaduki/rime
 def _RunReferenceSolution(self, ui):
     """Run the reference solution to generate reference outputs."""
     reference_solution = self.problem.reference_solution
     if reference_solution is None:
         ui.errors.Error(self, 'Reference solution unavailable')
         yield False
     testcases = self.ListTestCases()
     results = yield taskgraph.TaskBranch([
         self._RunReferenceSolutionOne(reference_solution, testcase, ui)
         for testcase in testcases
     ])
     if not all(results):
         yield False
     ui.console.PrintAction('REFRUN', reference_solution)
     yield True
示例#15
0
文件: testset.py 项目: okaduki/rime
    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')
        yield result
示例#16
0
 def _GenerateWiki(self, ui):
     yield self.Clean(ui)
     # Get system information.
     rev = builtin_commands.getoutput('svnversion')
     username = getpass.getuser()
     hostname = socket.gethostname()
     # Generate content.
     wiki = (u'このセクションは wikify plugin により自動生成されています '
             u'(rev.%(rev)s, uploaded by %(username)s @ %(hostname)s)\n' % {
                 'rev': rev,
                 'username': username,
                 'hostname': hostname
             })
     wiki += u'|||CENTER:|CENTER:|CENTER:|CENTER:|CENTER:|c\n'
     wiki += u'|~問題|~担当|~解答|~入力|~出力|~入検|~出検|\n'
     results = yield taskgraph.TaskBranch(
         [self._GenerateWikiOne(problem, ui) for problem in self.problems])
     wiki += ''.join(results)
     yield wiki
示例#17
0
 def _GenerateWikiFull(self, ui):
     yield self.Clean(ui)  # 重すぎるときはコメントアウト
     # Get system information.
     rev = builtin_commands.getoutput('svnversion')
     username = getpass.getuser()
     hostname = socket.gethostname()
     # Generate content.
     wiki = (u'#contents\n'
             u'このセクションは wikify_full plugin により自動生成されています '
             u'(rev.%(rev)s, uploaded by %(username)s @ %(hostname)s)\n' % {
                 'rev': rev,
                 'username': username,
                 'hostname': hostname
             })
     results = yield taskgraph.TaskBranch([
         self._GenerateWikiFullOne(problem, ui) for problem in self.problems
     ])
     wiki += ''.join(results)
     yield wiki
示例#18
0
文件: testset.py 项目: okaduki/rime
 def _TestSolutionWithChallengeCases(self, solution, ui):
     """Test a wrong solution which has specified challenge cases."""
     all_testcases = self.ListTestCases()
     challenge_infiles = [
         os.path.join(self.out_dir, infile)
         for infile in set(solution.challenge_cases)
     ]
     testcases = []
     for infile in challenge_infiles:
         matched_testcases = [
             testcase for testcase in all_testcases
             if testcase.infile == infile
         ]
         if not matched_testcases:
             ui.errors.Error(solution,
                             'Challenge case not found: %s' % infile)
             result = test.TestsetResult(self, solution, [])
             result.Finalize(False, 'Challenge case not found: %s' % infile)
             yield result
         elif len(matched_testcases) >= 2:
             ui.errors.Error(solution,
                             'Multiple challenge cases found: %s' % infile)
             result = test.TestsetResult(self, solution, [])
             result.Finalize(False,
                             'Multiple challenge cases found: %s' % infile)
             yield result
         testcases.append(matched_testcases[0])
     # Try challenge cases.
     result = test.TestsetResult(self, solution, testcases)
     yield taskgraph.TaskBranch([
         self._TestSolutionWithChallengeCasesOne(
             solution, testcase, result, ui) for testcase in testcases
     ],
                                unsafe_interrupt=True)
     if not result.IsFinalized():
         result.Finalize(True, 'Expectedly failed all challenge cases')
     yield result
示例#19
0
 def Build(self, ui):
     """Build all problems."""
     results = yield taskgraph.TaskBranch(
         [problem.Build(ui) for problem in self.problems])
     yield all(results)
示例#20
0
文件: commands.py 项目: tokoharu/rime
 def Submit(self, ui):
     results = yield taskgraph.TaskBranch(
         [problem.Submit(ui) for problem in self.problems])
     yield all(results)
示例#21
0
文件: commands.py 项目: tokoharu/rime
 def Upload(self, ui):
     results = yield taskgraph.TaskBranch(
         [problem.Upload(ui) for problem in self.problems])
     yield all(results)
示例#22
0
文件: commands.py 项目: tokoharu/rime
 def Pack(self, ui):
     results = yield taskgraph.TaskBranch(
         [problem.Pack(ui) for problem in self.problems])
     yield all(results)
示例#23
0
文件: commands.py 项目: tokoharu/rime
 def Submit(self, ui):
     results = yield taskgraph.TaskBranch(
         [solution.Submit(ui) for solution in self.solutions])
     yield all(results)
示例#24
0
文件: commands.py 项目: tokoharu/rime
 def Pack(self, ui):
     results = yield taskgraph.TaskBranch(
         [testset.Pack(ui) for testset in self.testsets])
     yield all(results)
示例#25
0
    def _GenerateHtmlFull(self, ui):
        # yield self.Clean(ui) # 重すぎるときはコメントアウト

        # Get system information.
        rev = SafeUnicode(
            builtin_commands.getoutput('git show -s --oneline').replace(
                '\n', ' ').replace('\r', ' '))
        username = getpass.getuser()
        hostname = socket.gethostname()

        header = u'<!DOCTYPE html>\n<html lang="ja"><head>'
        header += (
            u'<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com'
            '/bootstrap/3.2.0/css/bootstrap.min.css"></head>\n<body>')
        info = u'このセクションは htmlfy_full plugin により自動生成されています '
        info += (u'(rev.%(rev)s, uploaded by %(username)s @ %(hostname)s)\n' %
                 {
                     'rev': rev,
                     'username': username,
                     'hostname': hostname
                 })
        footer = u'</body></html>'

        # Generate content.
        html = u'<h2>Summary</h2>\n<table class="table">\n'
        html += (u'<thead><tr><th>問題</th><th>担当</th><th>解答</th><th>入力</th>'
                 u'<th>出力</th><th>入検</th><th>出検</th></tr></thead>\n')

        htmlFull = u'<h2>Detail<h2>\n'

        results = yield taskgraph.TaskBranch([
            self._GenerateHtmlFullOne(problem, ui) for problem in self.problems
        ])
        (htmlResults, htmlFullResults) = zip(*results)
        html += '<tbody>' + ''.join(htmlResults) + '</tbody></table>\n'
        htmlFull += ''.join(htmlFullResults)

        cc = os.getenv('CC', 'gcc')
        cxx = os.getenv('CXX', 'g++')
        java_home = os.getenv('JAVA_HOME')
        if java_home is not None:
            java = os.path.join(java_home, 'bin/java')
            javac = os.path.join(java_home, 'bin/javac')
        else:
            java = 'java'
            javac = 'javac'
        environments = '<h2>Environments</h2>\n<dl class="dl-horizontal">\n'
        environments += (
            '<dt>gcc:</dt><dd>' +
            builtin_commands.getoutput('{0} --version'.format(cc)) + '</dd>\n')
        environments += ('<dt>g++:</dt><dd>' + builtin_commands.getoutput(
            '{0} --version'.format(cxx)) + '</dd>\n')
        environments += ('<dt>javac:</dt><dd>' + builtin_commands.getoutput(
            '{0} -version'.format(javac)) + '</dd>\n')
        environments += ('<dt>java:</dt><dd>' + builtin_commands.getoutput(
            '{0} -version'.format(java)) + '</dd>\n')
        environments += '</dl>\n'

        errors = ''
        if ui.errors.HasError() or ui.errors.HasWarning():
            errors = '<h2>Error Messages</h2>\n<dl class="dl-horizontal">\n'
            if ui.errors.HasError():
                errors += '<dt class="danger">ERROR:</dt><dd><ul>\n'
                for e in ui.errors.errors:
                    errors += '<li>' + e + '</li>\n'
                errors += '</ul></dt>\n'
            if ui.errors.HasWarning():
                errors += '<dt class="warning">WARNING:</dt><dd><ul>\n'
                for e in ui.errors.warnings:
                    errors += '<li>' + e + '</li>\n'
                errors += '</ul></dd>\n'
            errors += '</dl>\n'

        yield header + info + html + environments + errors + htmlFull + footer
示例#26
0
文件: problem.py 项目: okaduki/rime
 def Build(self, ui):
     """Build all solutions and the testset."""
     results = yield taskgraph.TaskBranch(
         [solution.Build(ui)
          for solution in self.solutions] + [self.testset.Build(ui)])
     yield all(results)
示例#27
0
 def Test(self, ui):
     """Run tests in the project."""
     results = yield taskgraph.TaskBranch(
         [problem.Test(ui) for problem in self.problems])
     yield list(itertools.chain(*results))
示例#28
0
 def Clean(self, ui):
     """Clean the project."""
     results = yield taskgraph.TaskBranch(
         [problem.Clean(ui) for problem in self.problems])
     yield all(results)
示例#29
0
文件: testset.py 项目: okaduki/rime
 def _CompileJudges(self, ui):
     """Compile all judges."""
     results = yield taskgraph.TaskBranch(
         [self._CompileJudgeOne(judge, ui) for judge in self.judges])
     yield all(results)
示例#30
0
文件: problem.py 项目: okaduki/rime
 def TestSolution(self, solution, ui):
     """Run tests in the problem."""
     results = yield taskgraph.TaskBranch(
         [testset.TestSolution(solution, ui) for testset in self.testsets])
     yield list(itertools.chain(*results))