294
by mattgiuca
Added application: tutorialservice. Will be used as the Ajax backend for |
1 |
This file explains the parts that make up the test framework as well as how they interact.
|
2 |
||
3 |
---------------- |
|
4 |
parse_tute.py |
|
5 |
---------------- |
|
6 |
This file provides the function parse_tutorial_file which takes an xml specification of a tutorial problem file and returns a test suite object for that problem. It throws a ParseException if there was a problem parsing the file. |
|
7 |
||
8 |
||
9 |
---------------- |
|
10 |
TestFramework.py |
|
11 |
---------------- |
|
12 |
||
13 |
---TestSuite--- |
|
14 |
This class simply contains all the test cases and has a method (run_tests) to run the test cases and collate all the results. |
|
15 |
||
16 |
---TestCase--- |
|
17 |
This class contains sets of tests which contain the same inputs. It can optionally test an entire script or an individual function (these different types should be subclassed from a common base class). |
|
18 |
||
19 |
When given an attempt file (with the run method) this class runs both the solution and the attempt file and passes the outputs to its test parts. It then colates and returns the results. |
|
20 |
||
21 |
The inputs may be stdin (string), files (filename and file data pairs), or global variables (name-value pairs). Additionally, function tests have arguments with optional names. The files are put into a TestFilespace. |
|
22 |
||
23 |
The method _initialise_global_space determines how the global space is modified before running the code to be tested. Currently it simply defines the functions file, open and raw_input (but doesn't overwrite the definitions in __builtins__. |
|
24 |
||
25 |
---TestCasePart--- |
|
26 |
This implements a comparision test between the solution output and the attemp output. The run method does all the comparisons, then returns the result. |
|
27 |
||
28 |
Currently returns the empty string if the test passes, or else an error message. |
|
29 |
||
30 |
This class contains a method validate_functions, which evaluates all comparison and normalisation function, and ensures they are valid. It must be called after the include code is available in the testsuite, but before the tests are run. |
|
31 |
||
32 |
---TestFilespace--- |
|
33 |
This class is used by the test framework by replacing the user's file and open methods with the openfile method of an instance of this class. |
|
34 |
||
35 |
The core of this class is a dictionary that maps filenames (strings) to file data (also strings). |
|
36 |
||
37 |
When a file is opened (with the openfile method), a TestStringIO object is created, which attempts to emulate the all the read/write/append modes of fopen. This has not been thoroughly tested, but a few tests are present in filespace_test.py. |
|
38 |
||
39 |
Currently, a file cannot be opened more than once without closing it. Removing this restriction is not difficult, but then the actual effect of file operations becomes ambiguous. Simplest way would be to not tracked opened files which are read only. |
|
40 |
||
41 |
||
42 |
---TestStringIO--- |
|
43 |
This class acts like StringIO objects, but raise an error if a file operation is not allowed with the current mode. The flush method writes the modified contents back to the filespace. The close method also flushes the current content, then tells the filespace it is no longer open. |
|
44 |
||
45 |
||
46 |
||
47 |
To change the format of the results, change: |
|
48 |
TestCasePart.run |
|
49 |
TestCase.run |
|
50 |
TestSuite.run |
|
51 |
||
52 |
To change how the global space is initialised, change: |
|
53 |
TestCase._initialise_global_space |