~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/worksheet/utils.py

  • Committer: William Grant
  • Date: 2009-05-14 10:38:10 UTC
  • Revision ID: grantw@unimelb.edu.au-20090514103810-ib48aqxkocu1unkz
Tags: 0.1.9.13
Add some headings to ProjectView.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
This module provides functions for tutorial and worksheet computations.
24
24
"""
25
25
 
26
 
import os.path
27
 
 
28
26
from storm.locals import And, Asc, Desc, Store
29
27
import genshi
30
28
 
31
29
import ivle.database
32
30
from ivle.database import ExerciseAttempt, ExerciseSave, Worksheet, \
33
31
                          WorksheetExercise, Exercise
34
 
import ivle.webapp.tutorial.test
35
32
 
36
 
__all__ = ['ExerciseNotFound', 'get_exercise_status',
37
 
           'get_exercise_stored_text', 'get_exercise_attempts',
38
 
           'get_exercise_attempt', 'test_exercise_submission',
 
33
__all__ = ['get_exercise_status', 'get_exercise_stored_text',
 
34
           'get_exercise_attempts', 'get_exercise_attempt',
39
35
          ]
40
36
 
41
 
class ExerciseNotFound(Exception):
42
 
    pass
43
 
 
44
37
def get_exercise_status(store, user, worksheet_exercise, as_of=None):
45
38
    """Given a storm.store, User and Exercise, returns information about
46
39
    the user's performance on that problem.
275
268
                Exercise.id == exerciseid
276
269
            ).one()
277
270
            if exercise is None:
278
 
                raise ExerciseNotFound(exerciseid)
 
271
                raise NotFound()
279
272
            worksheet_exercise = WorksheetExercise()
280
273
            worksheet_exercise.worksheet_id = worksheet.id
281
274
            worksheet_exercise.exercise_id = exercise.id
284
277
        worksheet_exercise.seq_no = ex_num
285
278
        worksheet_exercise.optional = optional
286
279
 
287
 
 
288
 
def test_exercise_submission(config, user, exercise, code):
289
 
    """Test the given code against an exercise.
290
 
 
291
 
    The code is run in a console process as the provided user.
292
 
    """
293
 
    # Start a console to run the tests on
294
 
    jail_path = os.path.join(config['paths']['jails']['mounts'],
295
 
                             user.login)
296
 
    working_dir = os.path.join("/home", user.login)
297
 
    cons = ivle.console.Console(config, user.unixid, jail_path,
298
 
                                working_dir)
299
 
 
300
 
    # Parse the file into a exercise object using the test suite
301
 
    exercise_obj = ivle.webapp.tutorial.test.parse_exercise_file(
302
 
        exercise, cons)
303
 
 
304
 
    # Run the test cases. Get the result back as a JSONable object.
305
 
    # Return it.
306
 
    test_results = exercise_obj.run_tests(code)
307
 
 
308
 
    # Close the console
309
 
    cons.close()
310
 
 
311
 
    return test_results