diff options
author | adityacp | 2018-04-05 15:30:01 +0530 |
---|---|---|
committer | adityacp | 2018-04-05 15:30:01 +0530 |
commit | 032d496c7fa7298a0748885b0f1c8e2c24af67d8 (patch) | |
tree | 1cacc6b570ddbc4c8de172ced8e494c8ac655f0d /yaksh/grader.py | |
parent | f5c24ccf8b0bde0fe5726728a64f1e3638cf170d (diff) | |
download | online_test-032d496c7fa7298a0748885b0f1c8e2c24af67d8.tar.gz online_test-032d496c7fa7298a0748885b0f1c8e2c24af67d8.tar.bz2 online_test-032d496c7fa7298a0748885b0f1c8e2c24af67d8.zip |
Change error_messages.py, python_assertion_evaluator.py and grader.py
- Pep8 changes
- Show code error message along with test case
- Add nose in python exec scope
Diffstat (limited to 'yaksh/grader.py')
-rw-r--r-- | yaksh/grader.py | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/yaksh/grader.py b/yaksh/grader.py index 38cce8d..a721236 100644 --- a/yaksh/grader.py +++ b/yaksh/grader.py @@ -1,22 +1,12 @@ #!/usr/bin/env python from __future__ import unicode_literals import sys -import pwd import os -import stat import contextlib -from os.path import isdir, dirname, abspath, join, isfile, exists +from os.path import dirname, abspath import signal import traceback -from multiprocessing import Process, Queue -import subprocess -import re -try: - from SimpleXMLRPCServer import SimpleXMLRPCServer -except ImportError: - # The above import will not work on Python-3.x. - from xmlrpc.server import SimpleXMLRPCServer # Local imports from .settings import SERVER_TIMEOUT @@ -26,11 +16,13 @@ from .error_messages import prettify_exceptions MY_DIR = abspath(dirname(__file__)) registry = None + # Raised when the code times-out. # c.f. http://pguides.net/python/timeout-a-function class TimeoutException(Exception): pass + @contextlib.contextmanager def change_dir(path): cur_dir = abspath(dirname(MY_DIR)) @@ -75,7 +67,6 @@ class Grader(object): self.timeout_msg = msg self.in_dir = in_dir if in_dir else MY_DIR - def evaluate(self, kwargs): """Evaluates given code with the test cases based on given arguments in test_case_data. @@ -122,7 +113,6 @@ class Grader(object): test_case_instances.append(test_case_instance) return test_case_instances - def safe_evaluate(self, test_case_instances): """ Handles code evaluation along with compilation, signal handling @@ -155,20 +145,19 @@ class Grader(object): test_case_instance.teardown() except TimeoutException: - error.append(prettify_exceptions("TimeoutException", - self.timeout_msg - ) - ) + error.append( + prettify_exceptions("TimeoutException", self.timeout_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] - error.append(prettify_exceptions(exc_type.__name__, - str(exc_value), - "".join(tb_list), - ) - ) + error.append( + prettify_exceptions( + exc_type.__name__, str(exc_value), "".join(tb_list) + ) + ) finally: # Set back any original signal handler. set_original_signal_handler(prev_handler) |