summaryrefslogtreecommitdiff
path: root/yaksh/code_evaluator.py
diff options
context:
space:
mode:
authorankitjavalkar2016-11-02 16:02:03 +0530
committerankitjavalkar2016-11-10 12:43:14 +0530
commit053e27000540396b84c26d5a5f593d4389e0787a (patch)
tree0d48b337b2bc1e615b436784d78edf2daba08791 /yaksh/code_evaluator.py
parent7ae8584a4f4d095e005d6239102c0f26611ac006 (diff)
downloadonline_test-053e27000540396b84c26d5a5f593d4389e0787a.tar.gz
online_test-053e27000540396b84c26d5a5f593d4389e0787a.tar.bz2
online_test-053e27000540396b84c26d5a5f593d4389e0787a.zip
dd basic partial marking feature per test case
Diffstat (limited to 'yaksh/code_evaluator.py')
-rw-r--r--yaksh/code_evaluator.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py
index 79f616d..b404d57 100644
--- a/yaksh/code_evaluator.py
+++ b/yaksh/code_evaluator.py
@@ -82,14 +82,14 @@ class CodeEvaluator(object):
Returns
-------
- A tuple: (success, error message).
+ A tuple: (success, error message, marks).
"""
self.setup()
- success, err = self.safe_evaluate(**kwargs)
+ success, error, marks = self.safe_evaluate(**kwargs)
self.teardown()
- result = {'success': success, 'error': err}
+ result = {'success': success, 'error': error, 'marks': marks}
return result
# Private Protocol ##########
@@ -99,7 +99,7 @@ class CodeEvaluator(object):
os.makedirs(self.in_dir)
self._change_dir(self.in_dir)
- def safe_evaluate(self, user_answer, test_case_data, file_paths=None):
+ def safe_evaluate(self, user_answer, partial_grading, test_case_data, file_paths=None):
"""
Handles code evaluation along with compilation, signal handling
and Exception handling
@@ -108,32 +108,40 @@ class CodeEvaluator(object):
# Add a new signal handler for the execution of this code.
prev_handler = create_signal_handler()
success = False
+ error = ""
+ marks = 0.0
# Do whatever testing needed.
try:
for test_case in test_case_data:
success = False
self.compile_code(user_answer, file_paths, **test_case)
- success, err = self.check_code(user_answer, file_paths, **test_case)
- if not success:
- break
+ success, err, test_case_marks = self.check_code(user_answer,
+ file_paths,
+ partial_grading,
+ **test_case
+ )
+ if success:
+ marks += test_case_marks
+ else:
+ error += err + "\n"
except TimeoutException:
- err = self.timeout_msg
+ error = self.timeout_msg
except OSError:
msg = traceback.format_exc(limit=0)
- err = "Error: {0}".format(msg)
+ error = "Error: {0}".format(msg)
except Exception:
exc_type, exc_value, exc_tb = sys.exc_info()
tb_list = traceback.format_exception(exc_type, exc_value, exc_tb)
if len(tb_list) > 2:
del tb_list[1:3]
- err = "Error: {0}".format("".join(tb_list))
+ error = "Error: {0}".format("".join(tb_list))
finally:
# Set back any original signal handler.
set_original_signal_handler(prev_handler)
- return success, err
+ return success, error, marks
def teardown(self):
# Cancel the signal