diff options
Diffstat (limited to 'testapp')
-rwxr-xr-x | testapp/exam/code_server.py | 12 | ||||
-rw-r--r-- | testapp/exam/models.py | 28 | ||||
-rw-r--r-- | testapp/exam/templates/exam/add_question.html | 3 | ||||
-rw-r--r-- | testapp/exam/views.py | 11 | ||||
-rw-r--r-- | testapp/exam/xmlrpc_clients.py | 4 |
5 files changed, 49 insertions, 9 deletions
diff --git a/testapp/exam/code_server.py b/testapp/exam/code_server.py index 792197d..64d6a47 100755 --- a/testapp/exam/code_server.py +++ b/testapp/exam/code_server.py @@ -68,7 +68,7 @@ class CodeServer(object): 'have an infinite loop in your code.' % SERVER_TIMEOUT self.timeout_msg = msg - def run_python_code(self, answer, test_code, in_dir=None): + def run_python_code(self, answer, test_code, test_obj, in_dir=None): #### """Tests given Python function (`answer`) with the `test_code` supplied. If the optional `in_dir` keyword argument is supplied it changes the directory to that directory (it does not change @@ -123,7 +123,7 @@ class CodeServer(object): return success, err - def run_bash_code(self, answer, test_code, in_dir=None): + def run_bash_code(self, answer, test_code, test_obj, in_dir=None): #### """Tests given Bash code (`answer`) with the `test_code` supplied. The testcode should typically contain two lines, the first is a path to @@ -290,7 +290,7 @@ class CodeServer(object): stdnt_stdout+stdnt_stderr) return False, err - def run_c_code(self, answer, test_code, in_dir=None): + def run_c_code(self, answer, test_code, test_obj, in_dir=None): #### """Tests given C code (`answer`) with the `test_code` supplied. The testcode is a path to the reference code. @@ -442,7 +442,7 @@ class CodeServer(object): err = err + "\n" + stdnt_stderr return success, err - def run_cplus_code(self, answer, test_code, in_dir=None): + def run_cplus_code(self, answer, test_code, test_obj, in_dir=None): #### """Tests given C++ code (`answer`) with the `test_code` supplied. The testcode is a path to the reference code. @@ -504,7 +504,7 @@ class CodeServer(object): return success, err - def run_java_code(self, answer, test_code, in_dir=None): + def run_java_code(self, answer, test_code, test_obj, in_dir=None): #### """Tests given java code (`answer`) with the `test_code` supplied. The testcode is a path to the reference code. @@ -659,7 +659,7 @@ class CodeServer(object): stripped = stripped + c return ''.join(stripped) - def run_scilab_code(self, answer, test_code, in_dir=None): + def run_scilab_code(self, answer, test_code, test_obj, in_dir=None): #### """Tests given Scilab function (`answer`) with the `test_code` supplied. If the optional `in_dir` keyword argument is supplied it changes the directory to that directory (it does not change diff --git a/testapp/exam/models.py b/testapp/exam/models.py index 72fb51b..df3b485 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -62,6 +62,15 @@ class Question(models.Model): # Test cases for the question in the form of code that is run. test = models.TextField(blank=True) + #Test case Keyword arguments in dict form + test_keyword_args = models.TextField(blank=True) #### + + #Test case Positional arguments in list form + test_pos_args = models.TextField(blank=True) #### + + #Test case Expected answer in list form + test_expected_answer = models.TextField(blank=True) #### + # Any multiple choice options. Place one option per line. options = models.TextField(blank=True) @@ -396,3 +405,22 @@ class AssignmentUpload(models.Model): user = models.ForeignKey(Profile) assignmentQuestion = models.ForeignKey(Question) assignmentFile = models.FileField(upload_to=get_assignment_dir) + + +################################################################################ +class TestCase(models.Model): + question = models.ForeignKey(Question) + + # Test case Keyword arguments in dict form + test_keyword_args = models.TextField(blank=True) + + # Test case Positional arguments in list form + test_pos_args = models.TextField(blank=True) + + # Test case Expected answer in list form + test_expected_answer = models.TextField(blank=True) + + # Is this Test Case public or not. If it is not + # public it will not be visible to the user + # public = models.BooleanField(default=False) + diff --git a/testapp/exam/templates/exam/add_question.html b/testapp/exam/templates/exam/add_question.html index b0b22b1..b6ce908 100644 --- a/testapp/exam/templates/exam/add_question.html +++ b/testapp/exam/templates/exam/add_question.html @@ -28,6 +28,9 @@ <tr><td><strong>Rendered: </strong><td><p id='my'></p> <tr><td>Description: <td>{{ form.description}} {{form.description.errors}} <tr><td>Test: <td>{{ form.test }}{{form.test.errors}} + <tr><td>Test Keyword Arguments: <td>{{ form.test_keyword_args }}{{form.test.errors}} <!-- --> + <tr><td>Test Positional Arguments: <td>{{ form.test_pos_args }}{{form.test.errors}} <!-- --> + <tr><td>Test Expected Answer: <td>{{ form.test_expected_answer }}{{form.test.errors}} <!-- --> <tr><td>Snippet: <td>{{ form.snippet }}{{ form.snippet.errors }}</td></tD></td></tr> <tr><td>Tags: <td>{{ form.tags }} <tr><td id='label_option'>Options: <td>{{ form.options }} {{form.options.errors}} diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 11aca06..9b6ce69 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -959,9 +959,18 @@ def validate_answer(user, user_answer, question): elif question.type == 'code': user_dir = get_user_dir(user) success, message = code_server.run_code(user_answer, question.test, - user_dir, question.language) + question.test_keyword_args, question.test_pos_args, + question.test_expected_answer, user_dir, question.language) #### if success: correct = True + + #### + print "MESS>>>", question.test + print "POS>>>", question.test_pos_args + print "KEY>>>", question.test_keyword_args + print "EXP>>>", question.test_expected_answer + #### + return correct, success, message diff --git a/testapp/exam/xmlrpc_clients.py b/testapp/exam/xmlrpc_clients.py index 14ebf27..1aab8de 100644 --- a/testapp/exam/xmlrpc_clients.py +++ b/testapp/exam/xmlrpc_clients.py @@ -29,7 +29,7 @@ class CodeServerProxy(object): "scilab": "run_scilab_code", } - def run_code(self, answer, test_code, user_dir, language): + def run_code(self, answer, test_code, test_obj, keyword_args, pos_args, expected_answer, user_dir, language): #### """Tests given code (`answer`) with the `test_code` supplied. If the optional `in_dir` keyword argument is supplied it changes the directory to that directory (it does not change it back to the original when @@ -55,7 +55,7 @@ class CodeServerProxy(object): try: server = self._get_server() method = getattr(server, method_name) - result = method(answer, test_code, user_dir) + result = method(answer, test_code, test_obj, user_dir) #### except ConnectionError: result = [False, 'Unable to connect to any code servers!'] return result |