summaryrefslogtreecommitdiff
path: root/testapp/exam/python_code_evaluator.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2015-05-27 22:20:45 +0530
committerPrabhu Ramachandran2015-05-27 22:20:45 +0530
commitf3521eeb7dc05e4c529f8e50724ca5b3b8cc3f83 (patch)
treebf74cd706cad667f3b41a3e09d756fb9e73e898c /testapp/exam/python_code_evaluator.py
parenta83b57aee80959f11f96ad6a3a738c9fac906e26 (diff)
parent6f04127b10fad666a689b18db6a5a9aa1270d739 (diff)
downloadonline_test-f3521eeb7dc05e4c529f8e50724ca5b3b8cc3f83.tar.gz
online_test-f3521eeb7dc05e4c529f8e50724ca5b3b8cc3f83.tar.bz2
online_test-f3521eeb7dc05e4c529f8e50724ca5b3b8cc3f83.zip
Merge pull request #50 from hardythe1/remotes/origin/RemoveBuildout
Removed Buildout and related files & made a standard Django project
Diffstat (limited to 'testapp/exam/python_code_evaluator.py')
-rw-r--r--testapp/exam/python_code_evaluator.py61
1 files changed, 0 insertions, 61 deletions
diff --git a/testapp/exam/python_code_evaluator.py b/testapp/exam/python_code_evaluator.py
deleted file mode 100644
index 0c473cf..0000000
--- a/testapp/exam/python_code_evaluator.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python
-import sys
-import traceback
-import os
-from os.path import join
-import importlib
-
-# local imports
-from code_evaluator import CodeEvaluator
-
-
-class PythonCodeEvaluator(CodeEvaluator):
- """Tests the Python code obtained from Code Server"""
- # Private Protocol ##########
- def _check_code(self):
- success = False
-
- try:
- tb = None
- test_code = self._create_test_case()
- submitted = compile(self.user_answer, '<string>', mode='exec')
- g = {}
- exec submitted in g
- _tests = compile(test_code, '<string>', mode='exec')
- exec _tests in g
- except AssertionError:
- type, value, tb = sys.exc_info()
- info = traceback.extract_tb(tb)
- fname, lineno, func, text = info[-1]
- text = str(test_code).splitlines()[lineno-1]
- err = "{0} {1} in: {2}".format(type.__name__, str(value), text)
- else:
- success = True
- err = 'Correct answer'
-
- del tb
- return success, err
-
- def _create_test_case(self):
- """
- Create assert based test cases in python
- """
- test_code = ""
- if self.test:
- return self.test
- elif self.test_case_data:
- for test_case in self.test_case_data:
- pos_args = ", ".join(str(i) for i in test_case.get('pos_args')) \
- if test_case.get('pos_args') else ""
- kw_args = ", ".join(str(k+"="+a) for k, a
- in test_case.get('kw_args').iteritems()) \
- if test_case.get('kw_args') else ""
- args = pos_args + ", " + kw_args if pos_args and kw_args \
- else pos_args or kw_args
- 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