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.extension
22 from qm.fields import AttachmentField, TupleField, SetField
23
24
25
26
27
29 """A 'Runnable' can run on a 'Target'.
30
31 'Runnable' is an abstract base class for 'Test' and 'Resource'."""
32
34 """A 'ResourceField' contains the name of a resource.
35
36 The exact format of the name depends on the test database in use."""
37
42
43
44
45 EXTRA_ID = "qmtest_id"
46 """The name of the extra keyword argument to '__init__' that
47 specifies the name of the test or resource."""
48
49 EXTRA_DATABASE = "qmtest_database"
50 """The name of the extra keyword argument to '__init__' that
51 specifies the database containing the test or resource."""
52
53 RESOURCE_FIELD_ID = "resources"
54 """The name of the field that contains the resources on which this
55 test or resource depends."""
56
57 arguments = [
58 qm.fields.SetField(
59 ResourceField(
60 name = RESOURCE_FIELD_ID,
61 title = "Resources",
62 description = \
63 """Resources on which this test or resource depends.
64
65 Before this test or resource is executed, the
66 resources on which it depends will be set up.""",
67 not_empty_text = "true",
68 )),
69 ]
70
71
83
84
85
87 """Return the name of this test or resource.
88
89 'context' -- The 'Context' in which this entity is running.
90
91 returns -- The name of this test or resource."""
92
93 return self.__id
94
95
97 """Return the 'Database' in which this test or resource is stored.
98
99 returns -- The 'Database' in which this test or resource is
100 stored."""
101
102 return self.__database
103
104
106 """Return the 'Attachment's to this 'Runnable'.
107
108 returns -- A sequence consisting of the 'Attachment' objects
109 associated with this runnable."""
110
111 attachments = []
112 for f in qm.extension.get_class_arguments(self.__class__):
113 self.__GetAttachments(f,
114 getattr(self, f.GetName()),
115 attachments)
116 return attachments
117
118
120 """Return the 'Attachments' that are part of 'field'.
121
122 'field' -- The 'Field' being examined.
123
124 'value' -- The value of that 'Field' in 'self'.
125
126 'attachments' -- A sequence consisting of the attachments
127 found so far. Additional 'Attachment's are appended to this
128 sequence by this function."""
129
130 if isinstance(field, AttachmentField):
131 attachments.append(getattr(self, field.GetName()))
132 elif isinstance(field, TupleField):
133 subfields = field.GetSubfields()
134 for i in xrange(len(subfields)):
135 self.__GetAttachments(subfields[i], value[i],
136 attachments)
137 elif isinstance(field, SetField):
138 subfield = field.GetSubfields()[0]
139 for i in xrange(len(value)):
140 self.__GetAttachments(subfield, value[i],
141 attachments)
142
143 return
144