summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-08-31 15:39:19 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-08-31 15:39:19 +0200
commit7b98be750d401b2b6093d8de61e04c0e5f5fb764 (patch)
tree74177e0e90c459787bac13aa5409878a0c91c9d6 /server
parent0a307af35995c87e5e8f0851704e8a784a3ac380 (diff)
Add hint & test functions for PythonSession
Diffstat (limited to 'server')
-rw-r--r--server/python_session.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/server/python_session.py b/server/python_session.py
index 7a5d22a..24a06f1 100644
--- a/server/python_session.py
+++ b/server/python_session.py
@@ -2,6 +2,8 @@
import threading
import python.engine
+from db.models import Problem
+from . import problems
__all__ = ['PythonSession']
@@ -43,5 +45,24 @@ class PythonSession(object):
python.engine.destroy(self._interpreter)
self._interpreter = None
+ def hint(self, user_id, problem_id, program):
+ language, problem_group, problem = Problem.identifier(problem_id)
+
+ # Try problem-specific hints.
+ problem_module = problems.load_problem(language, problem_group, problem, 'common')
+ if hasattr(problem_module, 'hint'):
+ hints = problem_module.hint(program)
+ if hints:
+ return hints
+
+ # Finally return a generic "try thinking a bit" message.
+ return [{'id': 'no_hint'}]
+
def test(self, user_id, problem_id, program):
- return ['Python testing is not implemented yet']
+ language, problem_group, problem = Problem.identifier(problem_id)
+ problem_module = problems.load_problem(language, problem_group, problem, 'common')
+ try:
+ n_correct, n_all = problem_module.test(program)
+ return [{'id': 'test_results', 'args': {'passed': n_correct, 'total': n_all}}]
+ except AttributeError as ex:
+ return [{'id': 'test_results', 'args': {'passed': 0, 'total': 0}}]