def _TestOneCase(self, solution, testcase, ui): """Test a solution with one case. Cache results if option is set. Returns TestCaseResult. """ cache_file_name = os.path.join( solution.out_dir, os.path.splitext(os.path.basename(testcase.infile))[0] + consts.CACHE_EXT) solution_file_name = os.path.join(solution.src_dir, solution.code.src_name) cache_flag = (ui.options.cache_tests and files.GetModified(solution_file_name) < files.GetModified(cache_file_name) and files.GetModified(testcase.infile) < files.GetModified(cache_file_name)) if cache_flag: case_result_cache = files.ReadFile(cache_file_name) if case_result_cache is not None: j = json.loads(case_result_cache) if j['time'] is not None: j['time'] = float(j['time']) if j['verdict'] is not None: j['verdict'] = j['verdict'].encode('ascii') case_result = test.TestCaseResult(solution, testcase, None, None, True) case_result.time = j['time'] case_result.verdict = [ verdict for verdict in test.TestCaseResult.__dict__.values() if isinstance(verdict, test.TestVerdict) and verdict.msg == j['verdict'] ][0] yield case_result case_result = yield self._TestOneCaseNoCache(solution, testcase, ui) # always cache in json files.WriteFile( json.dumps({ 'verdict': case_result.verdict.msg, 'time': case_result.time }), cache_file_name) yield case_result
def GetCacheStamp(self): """Get timestamp of the stamp file. Returns datetime.datetime.min if not available. """ return files.GetModified(self.stamp_file)