From fd97b0391b7364927061487604b187541dab6510 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 20 Jun 2016 14:55:08 +0530 Subject: changed evaluators to support file based questions --- yaksh/bash_code_evaluator.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'yaksh/bash_code_evaluator.py') diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py index a0af0e2..c602ceb 100644 --- a/yaksh/bash_code_evaluator.py +++ b/yaksh/bash_code_evaluator.py @@ -9,6 +9,7 @@ import importlib # local imports from code_evaluator import CodeEvaluator +from copy_delete_files import CopyDeleteFiles class BashCodeEvaluator(CodeEvaluator): @@ -22,8 +23,11 @@ class BashCodeEvaluator(CodeEvaluator): # Delete the created file. super(BashCodeEvaluator, self).teardown() os.remove(self.submit_code_path) + if self.files_list: + file_delete = CopyDeleteFiles() + file_delete.delete_files(self.files_list) - def check_code(self, user_answer, test_case): + def check_code(self, user_answer, file_paths, test_case): """ Function validates student script using instructor script as reference. Test cases can optionally be provided. The first argument ref_path, is the path to instructor script, it is assumed to @@ -53,6 +57,10 @@ class BashCodeEvaluator(CodeEvaluator): clean_ref_code_path, clean_test_case_path = \ self._set_test_code_file_path(get_ref_path, get_test_case_path) + self.files_list = [] + if file_paths: + file_copy = CopyDeleteFiles() + self.files_list = file_copy.copy_files(file_paths) if not isfile(clean_ref_code_path): msg = "No file at %s or Incorrect path" % clean_ref_code_path return False, msg @@ -67,6 +75,7 @@ class BashCodeEvaluator(CodeEvaluator): return False, msg success = False + user_answer = user_answer.replace("\r", "") self.write_to_submit_code_file(self.submit_code_path, user_answer) if clean_test_case_path is None or "": @@ -114,6 +123,12 @@ class BashCodeEvaluator(CodeEvaluator): stderr=subprocess.PIPE ) proc, inst_stdout, inst_stderr = ret + if self.files_list: + file_delete = CopyDeleteFiles() + file_delete.delete_files(self.files_list) + if file_paths: + file_copy = CopyDeleteFiles() + self.files_list = file_copy.copy_files(file_paths) args = [self.submit_code_path] + \ [x for x in test_case.split()] ret = self._run_command(args, @@ -126,7 +141,7 @@ class BashCodeEvaluator(CodeEvaluator): return True, "Correct answer" else: err = ("Error:expected" - " %s, got %s").format(inst_stdout+inst_stderr, + " {0}, got {1}").format(inst_stdout+inst_stderr, stdnt_stdout+stdnt_stderr ) return False, err -- cgit From df9a893b91b4adb39f01b88f6b6d96359db37f47 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 11 Jul 2016 16:37:50 +0530 Subject: changed file module name in evaluators --- yaksh/bash_code_evaluator.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'yaksh/bash_code_evaluator.py') diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py index c602ceb..bce7f07 100644 --- a/yaksh/bash_code_evaluator.py +++ b/yaksh/bash_code_evaluator.py @@ -9,7 +9,7 @@ import importlib # local imports from code_evaluator import CodeEvaluator -from copy_delete_files import CopyDeleteFiles +from file_utils import copy_files, delete_files class BashCodeEvaluator(CodeEvaluator): @@ -23,9 +23,8 @@ class BashCodeEvaluator(CodeEvaluator): # Delete the created file. super(BashCodeEvaluator, self).teardown() os.remove(self.submit_code_path) - if self.files_list: - file_delete = CopyDeleteFiles() - file_delete.delete_files(self.files_list) + if self.files: + delete_files(self.files) def check_code(self, user_answer, file_paths, test_case): """ Function validates student script using instructor script as @@ -57,10 +56,9 @@ class BashCodeEvaluator(CodeEvaluator): clean_ref_code_path, clean_test_case_path = \ self._set_test_code_file_path(get_ref_path, get_test_case_path) - self.files_list = [] + self.files = [] if file_paths: - file_copy = CopyDeleteFiles() - self.files_list = file_copy.copy_files(file_paths) + self.files = copy_files(file_paths) if not isfile(clean_ref_code_path): msg = "No file at %s or Incorrect path" % clean_ref_code_path return False, msg @@ -123,12 +121,8 @@ class BashCodeEvaluator(CodeEvaluator): stderr=subprocess.PIPE ) proc, inst_stdout, inst_stderr = ret - if self.files_list: - file_delete = CopyDeleteFiles() - file_delete.delete_files(self.files_list) if file_paths: - file_copy = CopyDeleteFiles() - self.files_list = file_copy.copy_files(file_paths) + self.files = copy_files(file_paths) args = [self.submit_code_path] + \ [x for x in test_case.split()] ret = self._run_command(args, -- cgit