summaryrefslogtreecommitdiff
path: root/testapp
diff options
context:
space:
mode:
Diffstat (limited to 'testapp')
-rw-r--r--testapp/exam/bash_code_evaluator.py4
-rw-r--r--testapp/exam/code_evaluator.py8
-rwxr-xr-xtestapp/exam/code_server.py6
-rw-r--r--testapp/exam/cpp_code_evaluator.py19
-rw-r--r--testapp/exam/java_code_evaluator.py11
-rw-r--r--testapp/exam/models.py4
-rw-r--r--testapp/exam/python_code_evaluator.py7
-rw-r--r--testapp/exam/scilab_code_evaluator.py5
-rw-r--r--testapp/tests/__init__.py0
-rw-r--r--testapp/tests/test_bash_evaluation.py (renamed from testapp/test_bash_evaluation.py)1
-rw-r--r--testapp/tests/test_c_cpp_evaluation.py (renamed from testapp/test_c_cpp_evaluation.py)0
-rw-r--r--testapp/tests/test_code_evaluation.py (renamed from testapp/test_code_evaluation.py)0
-rw-r--r--testapp/tests/test_java_evaluation.py (renamed from testapp/test_java_evaluation.py)0
-rw-r--r--testapp/tests/test_python_evaluation.py (renamed from testapp/test_python_evaluation.py)0
-rw-r--r--testapp/tests/test_scilab_evaluation.py (renamed from testapp/test_scilab_evaluation.py)0
15 files changed, 28 insertions, 37 deletions
diff --git a/testapp/exam/bash_code_evaluator.py b/testapp/exam/bash_code_evaluator.py
index 7fcfb0f..23c0ae5 100644
--- a/testapp/exam/bash_code_evaluator.py
+++ b/testapp/exam/bash_code_evaluator.py
@@ -23,11 +23,11 @@ class BashCodeEvaluator(CodeEvaluator):
def _setup(self):
super(BashCodeEvaluator, self)._setup()
- self.set_file_as_executable(self.submit_path)
+ self._set_file_as_executable(self.submit_path)
get_ref_path, get_test_case_path = self.ref_code_path.strip().split(',')
get_ref_path = get_ref_path.strip()
get_test_case_path = get_test_case_path.strip()
- ref_path, test_case_path = self.set_test_code_file_path(get_ref_path,
+ ref_path, test_case_path = self._set_test_code_file_path(get_ref_path,
get_test_case_path)
return ref_path, self.submit_path, test_case_path
diff --git a/testapp/exam/code_evaluator.py b/testapp/exam/code_evaluator.py
index 1efd519..2a57257 100644
--- a/testapp/exam/code_evaluator.py
+++ b/testapp/exam/code_evaluator.py
@@ -22,7 +22,6 @@ class TimeoutException(Exception):
pass
-# Private Protocol ##########
def timeout_handler(signum, frame):
"""A handler for the ALARM signal."""
raise TimeoutException('Code took too long to run.')
@@ -49,9 +48,6 @@ def delete_signal_handler():
return
-###############################################################################
-# `TestCode` class.
-###############################################################################
class CodeEvaluator(object):
"""Tests the code obtained from Code Server"""
def __init__(self, test_case_data, test, language, user_answer,
@@ -150,12 +146,12 @@ class CodeEvaluator(object):
return submit_path
- def set_file_as_executable(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)
- def set_test_code_file_path(self, ref_path=None, test_case_path=None):
+ def _set_test_code_file_path(self, ref_path=None, test_case_path=None):
if ref_path and not ref_path.startswith('/'):
ref_path = join(MY_DIR, ref_path)
diff --git a/testapp/exam/code_server.py b/testapp/exam/code_server.py
index 3dd5072..580379f 100755
--- a/testapp/exam/code_server.py
+++ b/testapp/exam/code_server.py
@@ -32,12 +32,6 @@ import json
# Local imports.
from settings import SERVER_PORTS, SERVER_TIMEOUT, SERVER_POOL_PORT
from language_registry import set_registry
-# from evaluate_python_code import EvaluatePythonCode
-# from evaluate_c_code import EvaluateCCode
-# from evaluate_cpp_code import EvaluateCppCode
-# from evaluate_java_code import EvaluateJavaCode
-# from evaluate_scilab_code import EvaluateScilabCode
-# from evaluate_bash_code import EvaluateBashCode
MY_DIR = abspath(dirname(__file__))
diff --git a/testapp/exam/cpp_code_evaluator.py b/testapp/exam/cpp_code_evaluator.py
index 04efba8..15e2b13 100644
--- a/testapp/exam/cpp_code_evaluator.py
+++ b/testapp/exam/cpp_code_evaluator.py
@@ -12,19 +12,20 @@ from code_evaluator import CodeEvaluator
class CppCodeEvaluator(CodeEvaluator):
"""Tests the C code obtained from Code Server"""
- def __init__(self, test_case_data, test, language, user_answer,
- ref_code_path=None, in_dir=None):
- super(CppCodeEvaluator, self).__init__(test_case_data, test, language, user_answer,
- ref_code_path, in_dir)
+ def __init__(self, test_case_data, test, language, user_answer,
+ ref_code_path=None, in_dir=None):
+ super(CppCodeEvaluator, self).__init__(test_case_data, test, language,
+ user_answer, ref_code_path,
+ in_dir)
self.submit_path = self.create_submit_code_file('submit.c')
- self.test_case_args = self._setup()
+ self.test_case_args = self._setup()
# Private Protocol ##########
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)
+ ref_path, test_case_path = self._set_test_code_file_path(get_ref_path)
# Set file paths
c_user_output_path = os.getcwd() + '/output'
@@ -40,7 +41,8 @@ class CppCodeEvaluator(CodeEvaluator):
remove_user_output = c_user_output_path
remove_ref_output = c_ref_output_path
- return ref_path, self.submit_path, compile_command, compile_main, run_command_args, remove_user_output, remove_ref_output
+ return (ref_path, self.submit_path, compile_command, compile_main,
+ run_command_args, remove_user_output, remove_ref_output)
def _teardown(self):
# Delete the created file.
@@ -75,10 +77,8 @@ class CppCodeEvaluator(CodeEvaluator):
return False, 'No file at %s or Incorrect path' % submit_code_path
success = False
- # output_path = os.getcwd() + '/output'
ret = self._compile_command(compile_command)
proc, stdnt_stderr = ret
- # if self.language == "java":
stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr)
# Only if compilation is successful, the program is executed
@@ -86,7 +86,6 @@ class CppCodeEvaluator(CodeEvaluator):
if stdnt_stderr == '':
ret = self._compile_command(compile_main)
proc, main_err = ret
- # if self.language == "java":
main_err = self._remove_null_substitute_char(main_err)
if main_err == '':
diff --git a/testapp/exam/java_code_evaluator.py b/testapp/exam/java_code_evaluator.py
index 709a0a1..08ae208 100644
--- a/testapp/exam/java_code_evaluator.py
+++ b/testapp/exam/java_code_evaluator.py
@@ -14,7 +14,8 @@ class JavaCodeEvaluator(CodeEvaluator):
"""Tests the Java code obtained from Code Server"""
def __init__(self, test_case_data, test, language, user_answer,
ref_code_path=None, in_dir=None):
- super(JavaCodeEvaluator, self).__init__(test_case_data, test, language, user_answer,
+ super(JavaCodeEvaluator, self).__init__(test_case_data, test,
+ language, user_answer,
ref_code_path, in_dir)
self.submit_path = self.create_submit_code_file('Test.java')
self.test_case_args = self._setup()
@@ -23,7 +24,7 @@ class JavaCodeEvaluator(CodeEvaluator):
def _setup(self):
super(JavaCodeEvaluator, self)._setup()
- ref_path, test_case_path = self.set_test_code_file_path(self.ref_code_path)
+ ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
# Set file paths
java_student_directory = os.getcwd() + '/'
@@ -42,7 +43,8 @@ class JavaCodeEvaluator(CodeEvaluator):
remove_ref_output = "{0}{1}.class".format(java_student_directory,
java_ref_file_name)
- return ref_path, self.submit_path, compile_command, compile_main, run_command_args, remove_user_output, remove_ref_output
+ return (ref_path, self.submit_path, compile_command, compile_main,
+ run_command_args, remove_user_output, remove_ref_output)
def _teardown(self):
# Delete the created file.
@@ -77,10 +79,8 @@ class JavaCodeEvaluator(CodeEvaluator):
return False, 'No file at %s or Incorrect path' % submit_code_path
success = False
- # output_path = os.getcwd() + '/output'
ret = self._compile_command(compile_command)
proc, stdnt_stderr = ret
- # if self.language == "java":
stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr)
# Only if compilation is successful, the program is executed
@@ -88,7 +88,6 @@ class JavaCodeEvaluator(CodeEvaluator):
if stdnt_stderr == '':
ret = self._compile_command(compile_main)
proc, main_err = ret
- # if self.language == "java":
main_err = self._remove_null_substitute_char(main_err)
if main_err == '':
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index a60550c..c5043dc 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -20,8 +20,8 @@ class Profile(models.Model):
languages = (
("python", "Python"),
("bash", "Bash"),
- ("C", "C Language"),
- ("CPP", "C++ Language"),
+ ("c", "C Language"),
+ ("cpp", "C++ Language"),
("java", "Java Language"),
("scilab", "Scilab"),
)
diff --git a/testapp/exam/python_code_evaluator.py b/testapp/exam/python_code_evaluator.py
index 61eee66..0c473cf 100644
--- a/testapp/exam/python_code_evaluator.py
+++ b/testapp/exam/python_code_evaluator.py
@@ -52,7 +52,10 @@ class PythonCodeEvaluator(CodeEvaluator):
if test_case.get('kw_args') else ""
args = pos_args + ", " + kw_args if pos_args and kw_args \
else pos_args or kw_args
- tcode = "assert {0}({1}) == {2}".format(test_case.get('func_name'),
- args, test_case.get('expected_answer'))
+ function_name = test_case.get('func_name')
+ expected_answer = test_case.get('expected_answer')
+
+ tcode = "assert {0}({1}) == {2}".format(function_name, args,
+ expected_answer)
test_code += tcode + "\n"
return test_code
diff --git a/testapp/exam/scilab_code_evaluator.py b/testapp/exam/scilab_code_evaluator.py
index a4628a2..53640cc 100644
--- a/testapp/exam/scilab_code_evaluator.py
+++ b/testapp/exam/scilab_code_evaluator.py
@@ -14,7 +14,8 @@ class ScilabCodeEvaluator(CodeEvaluator):
"""Tests the Scilab code obtained from Code Server"""
def __init__(self, test_case_data, test, language, user_answer,
ref_code_path=None, in_dir=None):
- super(ScilabCodeEvaluator, self).__init__(test_case_data, test, language, user_answer,
+ super(ScilabCodeEvaluator, self).__init__(test_case_data, test,
+ language, user_answer,
ref_code_path, in_dir)
self.submit_path = self.create_submit_code_file('function.sci')
self.test_case_args = self._setup()
@@ -23,7 +24,7 @@ class ScilabCodeEvaluator(CodeEvaluator):
def _setup(self):
super(ScilabCodeEvaluator, self)._setup()
- ref_path, test_case_path = self.set_test_code_file_path(self.ref_code_path)
+ ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
return ref_path, # Return as a tuple
diff --git a/testapp/tests/__init__.py b/testapp/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/testapp/tests/__init__.py
diff --git a/testapp/test_bash_evaluation.py b/testapp/tests/test_bash_evaluation.py
index 5dce5fa..3ae3b0b 100644
--- a/testapp/test_bash_evaluation.py
+++ b/testapp/tests/test_bash_evaluation.py
@@ -1,4 +1,3 @@
-
import unittest
import os
from exam.bash_code_evaluator import BashCodeEvaluator
diff --git a/testapp/test_c_cpp_evaluation.py b/testapp/tests/test_c_cpp_evaluation.py
index b820963..b820963 100644
--- a/testapp/test_c_cpp_evaluation.py
+++ b/testapp/tests/test_c_cpp_evaluation.py
diff --git a/testapp/test_code_evaluation.py b/testapp/tests/test_code_evaluation.py
index fa2b1fa..fa2b1fa 100644
--- a/testapp/test_code_evaluation.py
+++ b/testapp/tests/test_code_evaluation.py
diff --git a/testapp/test_java_evaluation.py b/testapp/tests/test_java_evaluation.py
index d86d7b3..d86d7b3 100644
--- a/testapp/test_java_evaluation.py
+++ b/testapp/tests/test_java_evaluation.py
diff --git a/testapp/test_python_evaluation.py b/testapp/tests/test_python_evaluation.py
index 57e111c..57e111c 100644
--- a/testapp/test_python_evaluation.py
+++ b/testapp/tests/test_python_evaluation.py
diff --git a/testapp/test_scilab_evaluation.py b/testapp/tests/test_scilab_evaluation.py
index 072fff6..072fff6 100644
--- a/testapp/test_scilab_evaluation.py
+++ b/testapp/tests/test_scilab_evaluation.py