1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import qm
21 import qm.test.runnable
22
23
24
25
26
27 -class Resource(qm.test.runnable.Runnable):
28 """A 'Resource' sets up before a test and cleans up afterwards.
29
30 Some tests take a lot of work to set up. For example, a database
31 test that checks the result of SQL queries may require that the
32 database first be populated with a substantial number of records.
33 If there are many tests that all use the same set of records, it
34 would be wasteful to set up the database for each test. It would
35 be more efficient to set up the database once, run all of the
36 tests, and then remove the databases upon completion.
37
38 You can use a 'Resource' to gain this efficiency. If a test
39 depends on a resource, QMTest will ensure that the resource is
40 available before the test runs. Once all tests that depend on the
41 resource have been run QMTest will destroy the resource.
42
43 Each resource class (i.e., class derived from 'Resource')
44 describes a set of "arguments". Each argument has a name and a
45 type. The values of these arguments determine the design-time
46 parameters for the resource. See the documentation for the 'Test'
47 class for more complete information.
48
49 Each resource class also defines a 'SetUp' method that indicates how
50 to set up the resource, and a 'CleanUp' method that indicates how
51 to clean up afterwards.
52
53 'Resource' is an abstract class.
54
55 You can extend QMTest by providing your own resource class
56 implementation. If the resource classes that come with QMTest
57 cannot be used conveniently with your application domain, you may
58 wish to create a new resource class.
59
60 To create your own resource class, you must create a Python class
61 derived (directly or indirectly) from 'Resource'. The
62 documentation for each method of 'Resource' indicates whether you
63 must override it in your resource class implementation. Some
64 methods may be overridden, but do not need to be. You might want
65 to override such a method to provide a more efficient
66 implementation, but QMTest will work fine if you just use the
67 default version.
68
69 If QMTest calls a method on a resource and that method raises an
70 exception that is not caught within the method itself, QMTest will
71 catch the exception and continue processing."""
72
73 kind = "resource"
74
75 - def SetUp(self, context, result):
76 """Set up the resource.
77
78 'context' -- A 'Context' giving run-time parameters to the
79 resource. The resource may place additional variables into
80 the 'context'; these variables will be visible to tests that
81 depend on the resource.
82
83 'result' -- A 'Result' object. The outcome will be
84 'Result.PASS' when this method is called. The 'result' may be
85 modified by this method to indicate outcomes other than
86 'Result.PASS' or to add annotations.
87
88 This method should not return a value.
89
90 Derived classes must override this method."""
91
92 raise NotImplementedError
93
94
96 """Clean up the resource.
97
98 'result' -- A 'Result' object. The outcome will be
99 'Result.PASS' when this method is called. The 'result' may be
100 modified by this method to indicate outcomes other than
101 'Result.PASS' or to add annotations.
102
103 This method should not return a value.
104
105 Derived classes may override this method."""
106
107 pass
108