summaryrefslogtreecommitdiff
path: root/testapp
diff options
context:
space:
mode:
Diffstat (limited to 'testapp')
-rwxr-xr-xtestapp/exam/code_server.py18
-rw-r--r--testapp/exam/evaluate_bash.py6
-rw-r--r--testapp/exam/evaluate_c.py4
-rw-r--r--testapp/exam/evaluate_cpp.py4
-rw-r--r--testapp/exam/evaluate_java.py4
-rw-r--r--testapp/exam/evaluate_python.py5
-rw-r--r--testapp/exam/evaluate_scilab.py5
-rw-r--r--testapp/exam/registry.py14
-rw-r--r--testapp/exam/xmlrpc_clients.py2
9 files changed, 49 insertions, 13 deletions
diff --git a/testapp/exam/code_server.py b/testapp/exam/code_server.py
index ae68398..f5c5698 100755
--- a/testapp/exam/code_server.py
+++ b/testapp/exam/code_server.py
@@ -33,10 +33,14 @@ import json
import importlib
# Local imports.
from settings import SERVER_PORTS, SERVER_TIMEOUT, SERVER_POOL_PORT
+from registry import registry
MY_DIR = abspath(dirname(__file__))
+registry.register('python', )
+registry.register('py', MyTestCode)
+
def run_as_nobody():
"""Runs the current process as nobody."""
# Set the effective uid and to that of nobody.
@@ -137,25 +141,21 @@ class TestCode(object):
return result
def evaluate_code(self):
- pass
+ raise NotImplementedError("evaluate_code method not implemented")
def _create_submit_code_file(self, file_name):
""" Write the code (`answer`) to a file and set the file path"""
- # user_answer_file = {'c': 'submit.c', 'java': 'Test.java',
- # 'scilab': 'function.sci', 'cpp': 'submitstd.cpp',
- # 'bash': 'submit.sh'}
-
# File name/extension depending on the question language
submit_f = open(file_name, 'w')
submit_f.write(self.user_answer.lstrip())
submit_f.close()
submit_path = abspath(submit_f.name)
- if self.language == "bash":
- self._set_exec(submit_path)
+ if sfile_elf.language == "bash":
+ self._set_file_as_executable(submit_path)
return submit_path
- def _set_exec(self, fname):
+ def _set_file_as_executable(self, fname):
os.chmod(fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
| stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
| stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
@@ -219,7 +219,7 @@ class CodeServer(object):
self.port = port
self.queue = queue
- def checker(self, info_parameter, in_dir=None):
+ def check_code(self, info_parameter, in_dir=None):
"""Calls the TestCode Class to test the current code"""
info_parameter = json.loads(info_parameter)
test_parameter = info_parameter.get("test_parameter")
diff --git a/testapp/exam/evaluate_bash.py b/testapp/exam/evaluate_bash.py
index 4e79053..57c89ae 100644
--- a/testapp/exam/evaluate_bash.py
+++ b/testapp/exam/evaluate_bash.py
@@ -8,6 +8,8 @@ import importlib
# local imports
from code_server import TestCode
+from registry import registry
+
class EvaluateBash(TestCode):
"""Tests the Bash code obtained from Code Server"""
@@ -105,4 +107,6 @@ class EvaluateBash(TestCode):
else:
err = "Error:expected %s, got %s" % (inst_stdout+inst_stderr,
stdnt_stdout+stdnt_stderr)
- return False, err \ No newline at end of file
+ return False, err
+
+registry.register('bash', evaluate_bash, EvaluateBash) \ No newline at end of file
diff --git a/testapp/exam/evaluate_c.py b/testapp/exam/evaluate_c.py
index 93c3725..bbe0e87 100644
--- a/testapp/exam/evaluate_c.py
+++ b/testapp/exam/evaluate_c.py
@@ -8,6 +8,8 @@ import importlib
# local imports
from code_server import TestCode
+from registry import registry
+
class EvaluateC(TestCode):
"""Tests the C code obtained from Code Server"""
@@ -126,3 +128,5 @@ class EvaluateC(TestCode):
if ord(c) is not 26 and ord(c) is not 0:
stripped = stripped + c
return ''.join(stripped)
+
+registry.register('c', evaluate_c, EvaluateC) \ No newline at end of file
diff --git a/testapp/exam/evaluate_cpp.py b/testapp/exam/evaluate_cpp.py
index 1723d3b..87bd7a3 100644
--- a/testapp/exam/evaluate_cpp.py
+++ b/testapp/exam/evaluate_cpp.py
@@ -9,6 +9,8 @@ import importlib
# local imports
from evaluate_c import EvaluateC
from code_server import TestCode
+from registry import registry
+
class EvaluateCpp(EvaluateC, TestCode):
@@ -41,3 +43,5 @@ class EvaluateCpp(EvaluateC, TestCode):
os.remove(submit_path)
return success, err
+
+registry.register('cpp', evaluate_cpp, EvaluateCpp) \ No newline at end of file
diff --git a/testapp/exam/evaluate_java.py b/testapp/exam/evaluate_java.py
index 92969a3..f908102 100644
--- a/testapp/exam/evaluate_java.py
+++ b/testapp/exam/evaluate_java.py
@@ -9,6 +9,8 @@ import importlib
# local imports
from evaluate_c import EvaluateC
from code_server import TestCode
+from registry import registry
+
class EvaluateJava(EvaluateC, TestCode):
@@ -43,3 +45,5 @@ class EvaluateJava(EvaluateC, TestCode):
os.remove(submit_path)
return success, err
+
+registry.register('java', evaluate_java, EvaluateJava) \ No newline at end of file
diff --git a/testapp/exam/evaluate_python.py b/testapp/exam/evaluate_python.py
index 78d6fdf..18fde43 100644
--- a/testapp/exam/evaluate_python.py
+++ b/testapp/exam/evaluate_python.py
@@ -7,6 +7,7 @@ import importlib
# local imports
from code_server import TestCode
+from registry import registry
class EvaluatePython(TestCode):
"""Tests the Python code obtained from Code Server"""
@@ -49,4 +50,6 @@ class EvaluatePython(TestCode):
tcode = "assert {0}({1}) == {2}" \
.format(test_case.get('func_name'), args, test_case.get('expected_answer'))
test_code += tcode + "\n"
- return test_code \ No newline at end of file
+ return test_code
+
+registry.register('python', evaluate_python, EvaluatePython) \ No newline at end of file
diff --git a/testapp/exam/evaluate_scilab.py b/testapp/exam/evaluate_scilab.py
index e36d9d8..1874cf6 100644
--- a/testapp/exam/evaluate_scilab.py
+++ b/testapp/exam/evaluate_scilab.py
@@ -8,6 +8,7 @@ import importlib
# local imports
from code_server import TestCode
+from registry import registryz
class EvaluateScilab(TestCode):
@@ -76,4 +77,6 @@ class EvaluateScilab(TestCode):
for l in out.split('\n'):
if l.strip():
strip_out = strip_out+"\n"+l.strip()
- return strip_out \ No newline at end of file
+ return strip_out
+
+registry.register('scilab', evaluate_scilab, EvaluateScilab) \ No newline at end of file
diff --git a/testapp/exam/registry.py b/testapp/exam/registry.py
new file mode 100644
index 0000000..ef995ac
--- /dev/null
+++ b/testapp/exam/registry.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+class Registry(object):
+ def __init__(self):
+ self._registry = {}
+
+ def get_class(self, language):
+ return self._registry[language]
+
+ def register(self, language, cls):
+ self._registry[language] = cls
+
+
+registry = Registry() \ No newline at end of file
diff --git a/testapp/exam/xmlrpc_clients.py b/testapp/exam/xmlrpc_clients.py
index 5791dc6..33fbc57 100644
--- a/testapp/exam/xmlrpc_clients.py
+++ b/testapp/exam/xmlrpc_clients.py
@@ -50,7 +50,7 @@ class CodeServerProxy(object):
try:
server = self._get_server()
- result = server.checker(info_parameter, user_dir)
+ result = server.check_code(info_parameter, user_dir)
except ConnectionError:
result = json.dumps({'success': False, 'error': 'Unable to connect to any code servers!'})
return result