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.fields
22 import qm.test.database
23 import qm.test.result
24 import qm.test.runnable
25
26
27
28
29
30 __the_targets = []
31 """The global set of available targets."""
32
33
34
35
36
37
39 """A 'TargetGroupField' contains a target group pattern.
40
41 A target group pattern is a regular expression. A test will only be
42 run on a particular target if the target's group is matched by the
43 test's target group pattern."""
44
46 """Return a description of this field.
47
48 This description is used when displaying detailed help
49 information about the field."""
50
51
52 desc = qm.fields.TextField.GetDescription(self)
53
54 desc = desc + "\n\n**Available Target Groups**\n\n"
55 groups = [t.GetGroup() for t in get_targets()]
56 for g in groups:
57 desc = desc + " * " + g + "\n"
58
59 return desc
60
61
62
63 -class Test(qm.test.runnable.Runnable):
64 """A 'Test' is run to check for correct behavior.
65
66 A 'Test' performs some check on the system being tested, and
67 indicates whether the check was successful, or whether the
68 check failed.
69
70 Each test class (i.e., class derived from 'Test') describes a set
71 of "arguments". Each argument has a name and a type. The values
72 of these arguments determine the design-time parameters for the
73 test. For example, for a test class that executes program and
74 checks their exit codes, the arguments might consist of the
75 name of the program to execute, and the command-line arguments
76 that should be given to that program. QMTest uses the arguments
77 to prompt the user when creating a new test.
78
79 Each test class also defines a 'Run' method that indicates how
80 to run tests in that class. The 'Run' method is responsible for
81 actually performing the test and for reporting the results.
82
83 'Test' is an abstract class.
84
85 You can extend QMTest by providing your own test class
86 implementation. If the test classes that come with QMTest cannot
87 be used conveniently with your application domain, or if you would
88 like to report more detailed information about passing and failing
89 tests, you may wish to create a new test class.
90
91 To create your own test class, you must create a Python class
92 derived (directly or indirectly) from 'Test'. The documentation
93 for each method of 'Test' indicates whether you must override it
94 in your test class implementation. Some methods may be
95 overridden, but do not need to be. You might want to override
96 such a method to provide a more efficient implementation, but
97 QMTest will work fine if you just use the default version.
98
99 If QMTest calls a method on a test and that method raises an
100 exception that is not caught within the method itself, QMTest will
101 catch the exception and continue processing."""
102
104 """An 'OutcomeField' contains an outcome."""
105
106 - def __init__(self, name, **properties):
116
117
118
120 """A 'TestField' contains the name of a test.
121
122 The exact format of the name depends on the test database in use."""
123
128
129
130 arguments = [
131 TargetGroupField(
132 name="target_group",
133 title="Target Group Pattern",
134 description="""The targets on which this test can run.
135
136 A regular expression that indicates the targets on which
137 this test can be run. If the pattern matches a particular
138 group name, the test can be run on targets in that
139 group.""",
140 default_value=".*"
141 ),
142 qm.fields.SetField(
143 qm.fields.TupleField(
144 "prerequisites",
145 (TestField(
146 name = "test_id",
147 title = "Test",
148 description = """The name of the prerequisite test.""",
149 default_value = "",
150 ),
151 OutcomeField(
152 name = "outcome",
153 title = "Outcome",
154 description \
155 = """The required outcome for the prerequisite test.
156
157 If the outcome is different from that given here,
158 the dependent test will not be run.""",
159 )),
160 title="Prerequisite Tests",
161 description="""The tests on which this test depends.
162
163 Every test can depend on other tests. Those tests will be
164 run before this test. If the prerequisite test does not
165 have the outcome indicated, this test will not be run.""",
166 ))
167 ]
168
169 kind = "test"
170
171 PREREQUISITES_FIELD_ID = "prerequisites"
172 """The name of the field that contains the prerequisites on which
173 this test depends."""
174
175 - def Run(self, context, result):
176 """Run the test.
177
178 'context' -- A 'Context' giving run-time parameters to the
179 test.
180
181 'result' -- A 'Result' object. The outcome will be
182 'Result.PASS' when this method is called. The 'result' may be
183 modified by this method to indicate outcomes other than
184 'Result.PASS' or to add annotations.
185
186 This method should not return a value.
187
188 Derived classes must override this method."""
189
190 raise NotImplementedError
191
192
194 """Returns the pattern for the targets that can run this test.
195
196 returns -- A regular expression (represented as a string) that
197 indicates the targets on which this test can be run. If the
198 pattern matches a particular group name, the test can be run
199 on targets in that group."""
200
201 return self.target_group
202
203
204
205
206
207
209 """Set the available target.
210
211 'targets' -- A list of targets available for test execution."""
212
213 global __the_targets
214
215 __the_targets = targets
216
217
219 """Get the available target.
220
221 returns -- A list of targets available for test execution."""
222
223 return __the_targets
224
225
226
227
228
229
230
231
232