summaryrefslogtreecommitdiff
path: root/yaksh/grader.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2018-05-09 19:20:26 +0530
committerGitHub2018-05-09 19:20:26 +0530
commit28618863e1487627e24f24476afd0f7b12149bcb (patch)
treefd4a52c5f42aaad1170f6ae9af136abe520f9e49 /yaksh/grader.py
parent9248e11d935a0b80433bcc80f66fb4ad40f3adb3 (diff)
parent393a9d2a8ec116f6530512dfbe6e8769442667e3 (diff)
downloadonline_test-28618863e1487627e24f24476afd0f7b12149bcb.tar.gz
online_test-28618863e1487627e24f24476afd0f7b12149bcb.tar.bz2
online_test-28618863e1487627e24f24476afd0f7b12149bcb.zip
Merge pull request #471 from adityacp/fix_error_messages
Python Assertion Evaluation additions and changes
Diffstat (limited to 'yaksh/grader.py')
-rw-r--r--yaksh/grader.py40
1 files changed, 17 insertions, 23 deletions
diff --git a/yaksh/grader.py b/yaksh/grader.py
index c9dc8a2..320e7e7 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
@@ -157,20 +147,24 @@ class Grader(object):
test_case_instance.teardown()
except TimeoutException:
- error.append(prettify_exceptions("TimeoutException",
- self.timeout_msg
- )
- )
- except Exception:
+ error.append(
+ prettify_exceptions("TimeoutException", self.timeout_msg)
+ )
+ except Exception as e:
exc_type, exc_value, exc_tb = sys.exc_info()
tb_list = traceback.format_exception(exc_type, exc_value, exc_tb)
+ try:
+ line_no = e.lineno
+ except AttributeError:
+ line_no = traceback.extract_tb(exc_tb)[-1][1]
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),
+ line_no=line_no
+ )
+ )
finally:
# Set back any original signal handler.
set_original_signal_handler(prev_handler)