~ubuntu-branches/ubuntu/oneiric/checkbox/oneiric-updates

« back to all changes in this revision

Viewing changes to checkbox/variables.py

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Marc Tardif
  • Date: 2010-03-09 16:58:36 UTC
  • Revision ID: james.westby@ubuntu.com-20100309165836-26f22oe6ubppzx0d
Tags: 0.9
[ Marc Tardif ]
New upstream release (LP: #532882):
* Introduced job_prompt plugin to treat all jobs (suites, tests, etc.) as composites.
* Replaced the registry and resource scripts and centralized job iteration.
* Replaced dependency on dbus by using sudo/gksu/kdesudo instead.
* Replaced mktemp with mkdtemp for security purposes.
* Fixed strings in fingerprint and modem tests (LP: #457759)
* Fixed client side validation of Launchpad form (LP: #438671)
* Added device information to tags when reporting bugs with apport.
* Added shorthands for blacklist-file and whitelist-file.
* Added support for apport default configuration (LP: #465447)
* Added support for scrolled options list (LP: #411526)
* Added support for tests generated by suites to run as root.
* Added support for requirements in attachments.
* Added support for armv7l processor
* Added Autotest integration
* Added LTP integration
* Added Phoronix integration
* Added qa-regression-testing integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
 
84
84
 
85
85
class ConstantVariable(Variable):
86
 
    __slots__ = ("_item_factory")
 
86
    __slots__ = ("_item_factory",)
87
87
 
88
88
    def __init__(self, item_factory, *args, **kwargs):
89
89
        self._item_factory = item_factory
99
99
    __slots__ = ()
100
100
 
101
101
    def coerce(self, value):
102
 
        if isinstance(value, str):
 
102
        if isinstance(value, (str, unicode)):
103
103
            if re.match(r"(yes|true)", value, re.IGNORECASE):
104
104
                value = True
105
105
            elif re.match(r"(no|false)", value, re.IGNORECASE):
116
116
    __slots__ = ()
117
117
 
118
118
    def coerce(self, value):
119
 
        if not isinstance(value, str):
 
119
        if isinstance(value, unicode):
 
120
            value = str(value)
 
121
        elif not isinstance(value, str):
120
122
            raise ValueError("%r is not a str" % (value,))
121
123
 
122
124
        return value
146
148
    __slots__ = ()
147
149
 
148
150
    def coerce(self, value):
149
 
        if isinstance(value, str):
 
151
        if isinstance(value, (str, unicode)):
150
152
            value = int(value)
151
153
        elif not isinstance(value, (int, long)):
152
154
            raise ValueError("%r is not an int nor long" % (value,))
158
160
    __slots__ = ()
159
161
 
160
162
    def coerce(self, value):
161
 
        if isinstance(value, str):
 
163
        if isinstance(value, (str, unicode)):
162
164
            value = float(value)
163
165
        elif not isinstance(value, (int, long, float)):
164
166
            raise ValueError("%r is not a float" % (value,))
166
168
        return value
167
169
 
168
170
 
 
171
class TimeVariable(FloatVariable):
 
172
    __slots__ = ()
 
173
 
 
174
    pass
 
175
 
 
176
 
169
177
class ListVariable(Variable):
170
178
    __slots__ = ("_item_factory", "_separator")
171
179
 
176
184
 
177
185
    def coerce(self, values):
178
186
        item_factory = self._item_factory
179
 
        if isinstance(values, str):
 
187
        if isinstance(values, (str, unicode)):
180
188
            values = split(values, self._separator) if values else []
181
189
        elif not isinstance(values, (list, tuple)):
182
190
            raise ValueError("%r is not a list or tuple" % (values,))
183
191
 
184
 
        return [item_factory(value=v).get() for v in values]
 
192
        for i, v in enumerate(values):
 
193
            values[i] = item_factory(value=v).get()
 
194
 
 
195
        return values
185
196
 
186
197
 
187
198
class TupleVariable(ListVariable):
188
199
 
189
200
    def coerce(self, values):
190
 
        values = super(TupleVariable, self).coerce(values)
 
201
        values = super(TupleVariable, self).coerce(list(values))
191
202
        return tuple(values)
192
203
 
193
204
 
194
205
class AnyVariable(Variable):
195
 
    __slots__ = ("_schemas")
 
206
    __slots__ = ("_schemas",)
196
207
 
197
208
    def __init__(self, schemas, *args, **kwargs):
198
209
        self._schemas = schemas
221
232
    def coerce(self, value):
222
233
        if not isinstance(value, dict):
223
234
            raise ValueError("%r is not a dict." % (value,))
224
 
        new_dict = {}
225
 
        for k, v in value.items():
226
 
            new_dict[self._key_schema(value=k).get()] = \
 
235
 
 
236
        for k, v in value.iteritems():
 
237
            value[self._key_schema(value=k).get()] = \
227
238
                self._value_schema(value=v).get()
228
 
        return new_dict
 
239
        return value
229
240
 
230
241
 
231
242
class MapVariable(Variable):
232
 
    __slots__ = ("_schema")
 
243
    __slots__ = ("_schema",)
233
244
 
234
245
    def __init__(self, schema, *args, **kwargs):
235
246
        self._schema = schema
244
255
                raise ValueError("%r is not a valid key as per %r"
245
256
                                   % (k, self._schema))
246
257
 
247
 
        new_dict = {}
248
258
        for attribute, variable in self._schema.iteritems():
249
259
            old_value = value.get(attribute)
250
260
            try:
255
265
                    % (attribute, value, e))
256
266
 
257
267
            if attribute in value:
258
 
                new_dict[attribute] = new_value
 
268
                value[attribute] = new_value
259
269
 
260
 
        return new_dict
 
270
        return value
261
271
 
262
272
 
263
273
def get_variable(obj, attribute):