summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
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}}]