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.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py
index e4b961c..b5974d2 100644
--- a/yaksh/bash_code_evaluator.py
+++ b/yaksh/bash_code_evaluator.py
@@ -17,6 +17,7 @@ class BashCodeEvaluator(CodeEvaluator):
# Private Protocol ##########
def setup(self):
super(BashCodeEvaluator, self).setup()
+ self.files = []
self.submit_code_path = self.create_submit_code_file('submit.sh')
self._set_file_as_executable(self.submit_code_path)
@@ -27,7 +28,7 @@ class BashCodeEvaluator(CodeEvaluator):
delete_files(self.files)
super(BashCodeEvaluator, self).teardown()
- def check_code(self, user_answer, file_paths, test_case):
+ def check_code(self, user_answer, file_paths, partial_grading, test_case, weight):
""" 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
@@ -39,41 +40,44 @@ class BashCodeEvaluator(CodeEvaluator):
Returns
--------
+ success - Boolean, indicating if code was executed successfully, correctly
+ weight - Float, indicating total weight of all successful test cases
+ error - String, error message if success is false
- returns (True, "Correct answer") : If the student script passes all
+ returns (True, "Correct answer", 1.0) : If the student script passes all
test cases/have same output, when compared to the instructor script
- returns (False, error_msg): If the student script fails a single
+ returns (False, error_msg, 0.0): If the student script fails a single
test/have dissimilar output, when compared to the instructor script.
- Returns (False, error_msg): If mandatory arguments are not files or if
+ Returns (False, error_msg, 0.0): If mandatory arguments are not files or if
the required permissions are not given to the file(s).
-
"""
ref_code_path = test_case
+ success = False
+ test_case_weight = 0.0
+
get_ref_path, get_test_case_path = ref_code_path.strip().split(',')
get_ref_path = get_ref_path.strip()
get_test_case_path = get_test_case_path.strip()
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
+ return False, msg, 0.0
if not isfile(self.submit_code_path):
msg = "No file at %s or Incorrect path" % self.submit_code_path
- return False, msg
+ return False, msg, 0.0
if not os.access(clean_ref_code_path, os.X_OK):
msg = "Script %s is not executable" % clean_ref_code_path
- return False, msg
+ return False, msg, 0.0
if not os.access(self.submit_code_path, os.X_OK):
msg = "Script %s is not executable" % self.submit_code_path
- return False, msg
+ return False, msg, 0.0
- success = False
user_answer = user_answer.replace("\r", "")
self.write_to_submit_code_file(self.submit_code_path, user_answer)
@@ -91,19 +95,20 @@ class BashCodeEvaluator(CodeEvaluator):
)
proc, stdnt_stdout, stdnt_stderr = ret
if inst_stdout == stdnt_stdout:
- return True, "Correct answer"
+ test_case_weight = float(weight) if partial_grading else 0.0
+ return True, "Correct answer", test_case_weight
else:
err = "Error: expected %s, got %s" % (inst_stderr,
stdnt_stderr
)
- return False, err
+ return False, err, 0.0
else:
if not isfile(clean_test_case_path):
msg = "No test case at %s" % clean_test_case_path
- return False, msg
+ return False, msg, 0.0
if not os.access(clean_ref_code_path, os.R_OK):
msg = "Test script %s, not readable" % clean_test_case_path
- return False, msg
+ return False, msg, 0.0
# valid_answer is True, so that we can stop once a test case fails
valid_answer = True
# loop_count has to be greater than or equal to one.
@@ -133,10 +138,11 @@ class BashCodeEvaluator(CodeEvaluator):
proc, stdnt_stdout, stdnt_stderr = ret
valid_answer = inst_stdout == stdnt_stdout
if valid_answer and (num_lines == loop_count):
- return True, "Correct answer"
+ test_case_weight = float(weight) if partial_grading else 0.0
+ return True, "Correct answer", test_case_weight
else:
err = ("Error:expected"
" {0}, got {1}").format(inst_stdout+inst_stderr,
stdnt_stdout+stdnt_stderr
)
- return False, err
+ return False, err, 0.0