async def judge(self, cases_file, package): loop = get_event_loop() self.next(status=STATUS_JUDGING, progress=0) cases = list(read_cases(cases_file)) total_status = STATUS_ACCEPTED total_score = 0 total_time_usage_ns = 0 total_memory_usage_bytes = 0 judge_tasks = list() for case in cases: judge_tasks.append(loop.create_task(case.judge(package))) for index, judge_task in enumerate(judge_tasks): status, score, time_usage_ns, memory_usage_bytes, stderr = await shield(judge_task) if self.type == 1: judge_text = stderr.decode(encoding='utf-8', errors='replace') else: judge_text = '' self.next(status=STATUS_JUDGING, case={'status': status, 'score': score, 'time_ms': time_usage_ns // 1000000, 'memory_kb': memory_usage_bytes // 1024, 'judge_text': judge_text}, progress=(index + 1) * 100 // len(cases)) total_status = max(total_status, status) total_score += score total_time_usage_ns += time_usage_ns total_memory_usage_bytes = max(total_memory_usage_bytes, memory_usage_bytes) self.end(status=total_status, score=total_score, time_ms=total_time_usage_ns // 1000000, memory_kb=total_memory_usage_bytes // 1024)
def setUpClass(cls): try_init_cgroup() cls.cases = list( read_cases( open( path.join(path.dirname(__file__), 'testdata/decompose-sum.zip'), 'rb')))
def test_yaml_case(self): count = 0 with open(path.join(path.dirname(__file__), 'testdata/aplusb.zip'), 'rb') as file: for case in read_cases(file): self.assertEqual(case.time_limit_ns, 1000000000) self.assertEqual(case.memory_limit_bytes, 33554432) self.assertEqual(case.score, 10) self.assertEqual( sum(map(int, case.open_input().read().split())), int(case.open_output().read())) count += 1 self.assertEqual(count, 10)