diff options
Diffstat (limited to 'yaksh/code_evaluator.py')
-rw-r--r-- | yaksh/code_evaluator.py | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index f877952..7e2a729 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -8,7 +8,7 @@ import signal from multiprocessing import Process, Queue import subprocess import re -import json +# import json # Local imports. from settings import SERVER_TIMEOUT @@ -50,33 +50,39 @@ def delete_signal_handler(): class CodeEvaluator(object): """Tests the code obtained from Code Server""" - def __init__(self, test_case_data, test, language, user_answer, - ref_code_path=None, in_dir=None): + # def __init__(self, test_case_data, test, language, user_answer, + # ref_code_path=None, in_dir=None): + def __init__(self, in_dir, **kwargs): + + msg = 'Code took more than %s seconds to run. You probably '\ 'have an infinite loop in your code.' % SERVER_TIMEOUT self.timeout_msg = msg - self.test_case_data = test_case_data - self.language = language.lower() - self.user_answer = user_answer - self.ref_code_path = ref_code_path - self.test = test - self.in_dir = in_dir - self.test_case_args = None + # self.test_case_data = test_case_data + # self.language = language.lower() #@@@remove + # self.user_answer = user_answer #@@@specific to check-code + # self.ref_code_path = ref_code_path #@@@specific to check-code + # self.test = test #@@@specific to check-code + self.in_dir = in_dir #@@@Common for all, no change + self.test_case_args = None #@@@no change # Public Protocol ########## - @classmethod - def from_json(cls, language, json_data, in_dir): - json_data = json.loads(json_data) - test_case_data = json_data.get("test_case_data") - user_answer = json_data.get("user_answer") - ref_code_path = json_data.get("ref_code_path") - test = json_data.get("test") - - instance = cls(test_case_data, test, language, user_answer, ref_code_path, - in_dir) - return instance - - def evaluate(self): + # @classmethod + # def from_json(cls, language, json_data, in_dir): + # json_data = json.loads(json_data) + # # test_case_data = json_data.get("test_case_data") + # user_answer = json_data.get("user_answer") + # ref_code_path = json_data.get("ref_code_path") + # test = json_data.get("test") + + # # instance = cls(test_case_data, test, language, user_answer, ref_code_path, + # # in_dir) + # instance = cls(test, language, user_answer, ref_code_path, + # in_dir) + # return instance + + # def evaluate(self): + def evaluate(self, **kwargs): """Evaluates given code with the test cases based on given arguments in test_case_data. @@ -99,7 +105,8 @@ class CodeEvaluator(object): """ self.setup() - success, err = self.safe_evaluate(self.test_case_args) + # success, err = self.safe_evaluate(self.test_case_args) + success, err = self.safe_evaluate(**kwargs) self.teardown() result = {'success': success, 'error': err} @@ -109,15 +116,17 @@ class CodeEvaluator(object): def setup(self): self._change_dir(self.in_dir) - def safe_evaluate(self, args): + # def safe_evaluate(self, args): + def safe_evaluate(self, **kwargs): # Add a new signal handler for the execution of this code. prev_handler = create_signal_handler() success = False - args = args or [] + # args = args or [] # Do whatever testing needed. try: - success, err = self.check_code(*args) + # success, err = self.check_code(*args) + success, err = self.check_code(**kwargs) except TimeoutException: err = self.timeout_msg |