25
25
import sys, StringIO, copy
28
class TestCreationError(Exception):
29
"""An error occured while creating the test suite or one of its components"""
30
def __init__(self, reason):
37
class SolutionError(Exception):
38
"""Error in the provided solution"""
39
def __init__(self, exc_info):
40
cla, exc, trbk = exc_info
41
self.name = cla.__name__
42
self._detail = str(exc)
43
self._exc_info = exc_info
46
return {'name': self._name,
47
'detail': self._detail,
55
return "Error running solution: %s" %str(self._detail)
58
class TestError(Exception):
59
"""Runtime error in the testing framework outside of the provided or student code"""
60
def __init__(self, exc_info):
61
cla, exc, trbk = exc_info
62
self.name = cla.__name__
63
self._detail = str(exc)
64
self._exc_info = exc_info
70
return "Error testing solution against attempt: %s" %str(self._detail)
73
class AttemptError(Exception):
74
"""Runtime error in the student code"""
27
# student error or author error
28
# errors in student code get handled internally
29
# errors in solution code get passed up
30
class ScriptExecutionError(Exception):
31
"""Runtime error in the student code or solution code"""
75
32
def __init__(self, exc_info):
76
33
cla, exc, trbk = exc_info
77
34
self._name = cla.__name__
95
52
return self._name + " - " + str(self._detail)
55
class TestCreationError(Exception):
56
"""An error occured while creating the test suite or one of its components"""
57
def __init__(self, reason):
64
class TestError(Exception):
65
"""Runtime error in the testing framework outside of the provided or student code"""
66
def __init__(self, exc_info):
67
cla, exc, trbk = exc_info
68
self._name = cla.__name__
69
self._detail = str(exc)
70
self._exc_info = exc_info
76
return "Error testing solution against attempt: %s - %s" %(self._name, self._detail)
79
# raised when expected file not found in solution output
80
# Always gets caught and passed up as a TestError
81
class FileNotFoundError(Exception):
82
def __init__(self, filename):
83
self._filename = filename
86
return "File %s not found in output" %(self._filename)
89
# Error encountered when executing solution or attempt code
90
# Always gets caught and passed up in a ScriptExecutionError
98
91
class FunctionNotFoundError(Exception):
99
92
"""This error is returned when a function was expected in a
100
93
test case but was not found"""
262
255
# check files indicated by test
263
256
for (filename, (test_type, f)) in self._file_tests.items():
264
257
if filename not in solution_files:
265
raise SolutionError('File %s not found' %filename)
258
raise FileNotFoundError(filename)
266
259
elif filename not in attempt_files:
267
260
return filename + ' not found'
268
261
elif not self._check_output(solution_files[filename], attempt_files[filename], test_type, f):
396
389
raise FunctionNotFoundError(self._function)
397
390
attempt_data = self._run_function(lambda: global_space_copy[self._function](*self._list_args, **self._keyword_args))
399
case_dict['exception'] = AttemptError(sys.exc_info()).to_dict()
392
case_dict['exception'] = ScriptExecutionError(sys.exc_info()).to_dict()
400
393
case_dict['passed'] = False
406
399
# generate results
407
400
for test_part in self._parts:
408
result = test_part.run(solution_data, attempt_data)
402
result = test_part.run(solution_data, attempt_data)
404
raise TestError(sys.exc_info())
410
407
result_dict['description'] = test_part.get_description()
411
408
result_dict['passed'] = (result == '')