summaryrefslogtreecommitdiff
path: root/yaksh/hook_evaluator.py
diff options
context:
space:
mode:
authormaheshgudi2017-01-06 12:28:38 +0530
committermaheshgudi2017-01-09 18:10:30 +0530
commitf4b0ea30960ffe8e3ca4ffdd757c5df2f28d3371 (patch)
treeaf1a69b67417db030e8e80f76f8b82a21cb5a004 /yaksh/hook_evaluator.py
parent65f8f0f4dd867c1d1647712560e3aef73b8c921f (diff)
downloadonline_test-f4b0ea30960ffe8e3ca4ffdd757c5df2f28d3371.tar.gz
online_test-f4b0ea30960ffe8e3ca4ffdd757c5df2f28d3371.tar.bz2
online_test-f4b0ea30960ffe8e3ca4ffdd757c5df2f28d3371.zip
modified variable names in models and hook_evaluator
Diffstat (limited to 'yaksh/hook_evaluator.py')
-rw-r--r--yaksh/hook_evaluator.py34
1 files changed, 5 insertions, 29 deletions
diff --git a/yaksh/hook_evaluator.py b/yaksh/hook_evaluator.py
index 5480849..0ccdd5e 100644
--- a/yaksh/hook_evaluator.py
+++ b/yaksh/hook_evaluator.py
@@ -23,7 +23,7 @@ class HookEvaluator(BaseEvaluator):
self.partial_grading = metadata.get('partial_grading')
# Set test case data values
- self.test_case = test_case_data.get('code')
+ self.hook_code = test_case_data.get('hook_code')
self.weight = test_case_data.get('weight')
def teardown(self):
@@ -31,21 +31,9 @@ class HookEvaluator(BaseEvaluator):
if self.files:
delete_files(self.files)
- def compile_code(self):
- if self.file_paths:
- self.files = copy_files(self.file_paths)
- if self.exec_scope:
- return None
- else:
- submitted = compile(self.user_answer, '<string>', mode='exec')
- self.exec_scope = {}
- exec(submitted, self.exec_scope)
- return self.exec_scope
-
def check_code(self):
- """ Function validates user answer by running an assertion based test case
- against it
-
+ """ Function evaluates user answer by running a python based hook code
+ against it.
Returns
--------
Returns a tuple (success, error, test_case_weight)
@@ -67,21 +55,9 @@ class HookEvaluator(BaseEvaluator):
mark_fraction = 0.0
try:
tb = None
- _tests = compile(self.test_case, '<string>', mode='exec')
- exec(_tests, globals())
+ _tests = compile(self.hook_code, '<string>', mode='exec')
+ exec(_tests, locals())
success, err, mark_fraction = check_answer(self.user_answer)
- except AssertionError:
- type, value, tb = sys.exc_info()
- info = traceback.extract_tb(tb)
- fname, lineno, func, text = info[-1]
- text = str(self.test_case)
- err = "Expected Test Case:\n{0}\n" \
- "Error - {1} {2} in: {3}\n".format(
- self.test_case,
- type.__name__,
- str(value),
- text
- )
except TimeoutException:
raise
except Exception: