summaryrefslogtreecommitdiff
path: root/yaksh/bash_code_evaluator.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/bash_code_evaluator.py')
-rw-r--r--yaksh/bash_code_evaluator.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py
index a0af0e2..bce7f07 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 file_utils import copy_files, delete_files
class BashCodeEvaluator(CodeEvaluator):
@@ -22,8 +23,10 @@ class BashCodeEvaluator(CodeEvaluator):
# Delete the created file.
super(BashCodeEvaluator, self).teardown()
os.remove(self.submit_code_path)
+ if self.files:
+ delete_files(self.files)
- 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 +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 = []
+ if 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
@@ -67,6 +73,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 +121,8 @@ class BashCodeEvaluator(CodeEvaluator):
stderr=subprocess.PIPE
)
proc, inst_stdout, inst_stderr = ret
+ if 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,
@@ -126,7 +135,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