summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitjavalkar2016-03-04 14:55:09 +0530
committerankitjavalkar2016-05-05 18:57:52 +0530
commit3b56d8259d6aa8311f86e0561e40d0b17bc62534 (patch)
tree50e18e5f688fbeb195633073c36f9ce045d32e48
parent5ec456d5208df78ef87d0660e4bef430d553d65d (diff)
downloadonline_test-3b56d8259d6aa8311f86e0561e40d0b17bc62534.tar.gz
online_test-3b56d8259d6aa8311f86e0561e40d0b17bc62534.tar.bz2
online_test-3b56d8259d6aa8311f86e0561e40d0b17bc62534.zip
Language registry altered, Name cleanup:
- set_registry will only act when registry is None - _setup, _teardown and _check_code are setup,teardown,check_code - Corresponding name changes in evaluator modules
-rw-r--r--yaksh/code_evaluator.py16
-rwxr-xr-xyaksh/code_server.py9
-rw-r--r--yaksh/cpp_code_evaluator.py13
-rw-r--r--yaksh/java_code_evaluator.py13
-rw-r--r--yaksh/language_registry.py11
-rw-r--r--yaksh/python_code_evaluator.py4
-rw-r--r--yaksh/scilab_code_evaluator.py13
7 files changed, 42 insertions, 37 deletions
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py
index 381b2e8..f877952 100644
--- a/yaksh/code_evaluator.py
+++ b/yaksh/code_evaluator.py
@@ -98,18 +98,18 @@ class CodeEvaluator(object):
A tuple: (success, error message).
"""
- self._setup()
- success, err = self._evaluate(self.test_case_args)
- self._teardown()
+ self.setup()
+ success, err = self.safe_evaluate(self.test_case_args)
+ self.teardown()
result = {'success': success, 'error': err}
return result
# Private Protocol ##########
- def _setup(self):
+ def setup(self):
self._change_dir(self.in_dir)
- def _evaluate(self, args):
+ def safe_evaluate(self, args):
# Add a new signal handler for the execution of this code.
prev_handler = create_signal_handler()
success = False
@@ -117,7 +117,7 @@ class CodeEvaluator(object):
# Do whatever testing needed.
try:
- success, err = self._check_code(*args)
+ success, err = self.check_code(*args)
except TimeoutException:
err = self.timeout_msg
@@ -130,11 +130,11 @@ class CodeEvaluator(object):
return success, err
- def _teardown(self):
+ def teardown(self):
# Cancel the signal
delete_signal_handler()
- def _check_code(self):
+ def check_code(self):
raise NotImplementedError("check_code method not implemented")
def create_submit_code_file(self, file_name):
diff --git a/yaksh/code_server.py b/yaksh/code_server.py
index faf9c0d..2762f12 100755
--- a/yaksh/code_server.py
+++ b/yaksh/code_server.py
@@ -31,7 +31,7 @@ import re
import json
# Local imports.
from settings import SERVER_PORTS, SERVER_POOL_PORT
-from language_registry import set_registry, get_registry
+from language_registry import get_registry, registry
MY_DIR = abspath(dirname(__file__))
@@ -82,9 +82,10 @@ class CodeServer(object):
# Private Protocol ##########
def _create_evaluator_instance(self, language, json_data, in_dir):
"""Create instance of relevant EvaluateCode class based on language"""
- set_registry()
- registry = get_registry()
- cls = registry.get_class(language)
+ # set_registry()
+ registry1 = get_registry()
+ print registry
+ cls = registry1.get_class(language)
instance = cls.from_json(language, json_data, in_dir)
return instance
diff --git a/yaksh/cpp_code_evaluator.py b/yaksh/cpp_code_evaluator.py
index 7242884..129a1c8 100644
--- a/yaksh/cpp_code_evaluator.py
+++ b/yaksh/cpp_code_evaluator.py
@@ -17,11 +17,10 @@ class CppCodeEvaluator(CodeEvaluator):
super(CppCodeEvaluator, self).__init__(test_case_data, test, language,
user_answer, ref_code_path,
in_dir)
- self.test_case_args = self._setup()
+ self.test_case_args = self.setup()
- # Private Protocol ##########
- def _setup(self):
- super(CppCodeEvaluator, self)._setup()
+ def setup(self):
+ super(CppCodeEvaluator, self).setup()
get_ref_path = self.ref_code_path
ref_path, test_case_path = self._set_test_code_file_path(get_ref_path)
@@ -44,12 +43,12 @@ class CppCodeEvaluator(CodeEvaluator):
return (ref_path, self.submit_path, compile_command, compile_main,
run_command_args, remove_user_output, remove_ref_output)
- def _teardown(self):
+ def teardown(self):
# Delete the created file.
- super(CppCodeEvaluator, self)._teardown()
+ super(CppCodeEvaluator, self).teardown()
os.remove(self.submit_path)
- def _check_code(self, ref_code_path, submit_code_path, compile_command,
+ def check_code(self, ref_code_path, submit_code_path, compile_command,
compile_main, run_command_args, remove_user_output,
remove_ref_output):
""" Function validates student code using instructor code as
diff --git a/yaksh/java_code_evaluator.py b/yaksh/java_code_evaluator.py
index 4367259..6f39d71 100644
--- a/yaksh/java_code_evaluator.py
+++ b/yaksh/java_code_evaluator.py
@@ -17,11 +17,10 @@ class JavaCodeEvaluator(CodeEvaluator):
super(JavaCodeEvaluator, self).__init__(test_case_data, test,
language, user_answer,
ref_code_path, in_dir)
- self.test_case_args = self._setup()
+ self.test_case_args = self.setup()
- # Private Protocol ##########
- def _setup(self):
- super(JavaCodeEvaluator, self)._setup()
+ def setup(self):
+ super(JavaCodeEvaluator, self).setup()
ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
self.submit_path = self.create_submit_code_file('Test.java')
@@ -46,12 +45,12 @@ class JavaCodeEvaluator(CodeEvaluator):
return (ref_path, self.submit_path, compile_command, compile_main,
run_command_args, remove_user_output, remove_ref_output)
- def _teardown(self):
+ def teardown(self):
# Delete the created file.
- super(JavaCodeEvaluator, self)._teardown()
+ super(JavaCodeEvaluator, self).teardown()
os.remove(self.submit_path)
- def _check_code(self, ref_code_path, submit_code_path, compile_command,
+ def check_code(self, ref_code_path, submit_code_path, compile_command,
compile_main, run_command_args, remove_user_output,
remove_ref_output):
""" Function validates student code using instructor code as
diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py
index 76a23d7..ee311ec 100644
--- a/yaksh/language_registry.py
+++ b/yaksh/language_registry.py
@@ -3,11 +3,18 @@ import importlib
registry = None
-def set_registry():
+# def set_registry():
+# global registry
+# registry = _LanguageRegistry()
+
+def _set_registry():
global registry
- registry = _LanguageRegistry()
+ if registry is None:
+ registry = _LanguageRegistry()
+ return registry
def get_registry():
+ registry = _set_registry()
return registry
class _LanguageRegistry(object):
diff --git a/yaksh/python_code_evaluator.py b/yaksh/python_code_evaluator.py
index c87c420..3835b44 100644
--- a/yaksh/python_code_evaluator.py
+++ b/yaksh/python_code_evaluator.py
@@ -11,8 +11,8 @@ from code_evaluator import CodeEvaluator, TimeoutException
class PythonCodeEvaluator(CodeEvaluator):
"""Tests the Python code obtained from Code Server"""
- # Private Protocol ##########
- def _check_code(self):
+
+ def check_code(self):
success = False
try:
diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py
index 392cd45..a8bd4cd 100644
--- a/yaksh/scilab_code_evaluator.py
+++ b/yaksh/scilab_code_evaluator.py
@@ -20,23 +20,22 @@ class ScilabCodeEvaluator(CodeEvaluator):
# Removes all the commands that terminates scilab
self.user_answer, self.terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
- self.test_case_args = self._setup()
+ self.test_case_args = self.setup()
- # Private Protocol ##########
- def _setup(self):
- super(ScilabCodeEvaluator, self)._setup()
+ def setup(self):
+ super(ScilabCodeEvaluator, self).setup()
ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
self.submit_path = self.create_submit_code_file('function.sci')
return ref_path, # Return as a tuple
- def _teardown(self):
+ def teardown(self):
# Delete the created file.
- super(ScilabCodeEvaluator, self)._teardown()
+ super(ScilabCodeEvaluator, self).teardown()
os.remove(self.submit_path)
- def _check_code(self, ref_path):
+ def check_code(self, ref_path):
success = False
# Throw message if there are commmands that terminates scilab