diff options
author | ankitjavalkar | 2016-05-02 14:38:13 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-09 11:51:06 +0530 |
commit | d953f6f9e62671eeb5d6ea6498475167301dfe91 (patch) | |
tree | ca172e52de5e8dd04e97ce7acfa16ab577ab9d58 /yaksh/code_evaluator.py | |
parent | 23b7abd3c1125e4c875e214e4f673c48c4bf4752 (diff) | |
download | online_test-d953f6f9e62671eeb5d6ea6498475167301dfe91.tar.gz online_test-d953f6f9e62671eeb5d6ea6498475167301dfe91.tar.bz2 online_test-d953f6f9e62671eeb5d6ea6498475167301dfe91.zip |
- Fix tests
- Fix minor views.py
- Fix minor errors caused due to conflict resolution, rebasing
- Fix errors in forms, views
- Minor Button label change in addquestion.html
- Add snippet to question
- Remove commented code
Diffstat (limited to 'yaksh/code_evaluator.py')
-rw-r--r-- | yaksh/code_evaluator.py | 61 |
1 files changed, 6 insertions, 55 deletions
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index b7a523c..1c11c00 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -5,14 +5,13 @@ import os import stat from os.path import isdir, dirname, abspath, join, isfile, exists import signal +import traceback from multiprocessing import Process, Queue import subprocess import re -# import json # Local imports. from settings import SERVER_TIMEOUT - MY_DIR = abspath(dirname(__file__)) @@ -50,36 +49,12 @@ 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, in_dir=None): 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() #@@@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) - # instance = cls(test, language, user_answer, ref_code_path, - # in_dir) - # return instance - - # def evaluate(self): + self.in_dir = in_dir + def evaluate(self, **kwargs): """Evaluates given code with the test cases based on given arguments in test_case_data. @@ -103,7 +78,6 @@ class CodeEvaluator(object): """ self.setup() - # success, err = self.safe_evaluate(self.test_case_args) success, err = self.safe_evaluate(**kwargs) self.teardown() @@ -114,18 +88,13 @@ class CodeEvaluator(object): def setup(self): self._change_dir(self.in_dir) - # def safe_evaluate(self, args): - # def safe_evaluate(self, **kwargs): #@@@v2 def safe_evaluate(self, user_answer, test_case_data): # Add a new signal handler for the execution of this code. prev_handler = create_signal_handler() success = False - # args = args or [] # Do whatever testing needed. try: - # success, err = self.check_code(*args) - # success, err = self.check_code(**kwargs) #@@@v2 for test_case in test_case_data: self.compile_code(user_answer, **test_case) success, err = self.check_code(user_answer, **test_case) @@ -134,9 +103,9 @@ class CodeEvaluator(object): except TimeoutException: err = self.timeout_msg - except: - _type, value = sys.exc_info()[:2] - err = "Error: {0}".format(repr(value)) + except Exception: + err = "Error: {0}".format(traceback.format_exc(limit=0)) + finally: # Set back any original signal handler. set_original_signal_handler(prev_handler) @@ -198,24 +167,6 @@ class CodeEvaluator(object): raise return proc, stdout, stderr - # def _compile_command(self, cmd, *args, **kw): - # """Compiles C/C++/java code and returns errors if any. - # Run a command in a subprocess while blocking, the process is killed - # if it takes more than 2 seconds to run. Return the Popen object, the - # stderr. - # """ - # try: - # proc_compile = subprocess.Popen(cmd, shell=True, stdin=None, - # stdout=subprocess.PIPE, - # stderr=subprocess.PIPE) - # out, err = proc_compile.communicate() - # except TimeoutException: - # # Runaway code, so kill it. - # proc_compile.kill() - # # Re-raise exception. - # raise - # return proc_compile, err - def _change_dir(self, in_dir): if in_dir is not None and isdir(in_dir): os.chdir(in_dir) |