def check_path(self, path, files, zip_data):
logging.info("path={0}".format(path))
tally = defaultdict(int)
for filename in files:
if path is None or path == '':
testfile_path = os.path.abspath(os.path.join(self.ref_dir, filename))
testfile_key = filename
else:
testfile_path = os.path.abspath(os.path.join(self.ref_dir, path, filename))
testfile_key = os.path.join(path, filename)
# set up score value for matching output correctly
score = self.default_score
if path in self.path_score:
score = self.path_score[path]
logging.info("Checking {0}".format(testfile_key))
if testfile_key in zip_data:
with open(testfile_path, 'r') as ref:
ref_data = map(lambda x: x.strip(), ref.read().splitlines())
output_data = map(lambda x: x.strip(), zip_data[testfile_key].splitlines())
diff_lines = list(difflib.unified_diff(ref_data, output_data, "reference", "your-output", lineterm=''))
if len(diff_lines) > 0:
logging.info("Diff between reference and your output for {0}".format(testfile_key))
logging.info("{0}{1}".format(self.linesep, self.linesep.join(list(diff_lines))))
else:
tally['score'] += score
tally['num_correct'] += 1
logging.info("{0} Correct!".format(testfile_key))
tally['total'] += 1
self.perf[path] = dict(tally)
评论列表
文章目录