~roadmr/ubuntu/precise/checkbox/0.13.1

« back to all changes in this revision

Viewing changes to checkbox/properties.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif, Gabor Keleman
  • Date: 2009-08-19 15:36:05 UTC
  • Revision ID: james.westby@ubuntu.com-20090819153605-weo6htup3yi6zn0t
Tags: 0.8~alpha4
* New upstream version:
  * Changed icon.
  * Added timeout property to lock_prompt plugin.
  * Added concept of attachments to tests.
  * Added support for backslahes in templates to wrap lines.
  * Added support blacklisting and whitelisting both tests and suites.
  * Introduced the concept of jobs for suites, tests and attachments.
  * Removed upstart event which is no longer needed.
  * Replaced architecture and category with requires in test definitions.
* Fixed pygst dependency (LP: #334442)
* Fixed configuration file updates during install (LP: #330596)
* Fixed and expanded translations (LP: #347038)
* Fixed ignored system proxy settings (LP: #345548)
* Fixed parsing blank lines in templates (LP: #393907)
* Fixed escaping of lists (LP: #394001)
* Fixed timeout in manual tests (LP: #377986)
* Fixed CLI interface dialog.
* Fixed support for FreeDesktop XDG base directory specification (LP: #363549)
* Added general and package specific apport hooks

[ Gabor Keleman ]
* Fixed untranslated strings in tests (LP: #374666)
* Fixed untranslated last screen (LP: #374646)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
18
18
#
19
19
from checkbox.attribute import Attribute
20
 
from checkbox.variables import (BoolVariable, StringVariable,
21
 
    PathVariable, IntVariable, FloatVariable, ListVariable,
22
 
    VariableFactory, Variable, get_variable)
 
20
from checkbox.variables import (ConstantVariable, BoolVariable, StringVariable,
 
21
    PathVariable, UnicodeVariable, IntVariable, FloatVariable, ListVariable,
 
22
    TupleVariable, AnyVariable, DictVariable, MapVariable, VariableFactory,
 
23
    Variable, get_variable)
23
24
 
24
25
 
25
26
class Property(object):
66
67
 
67
68
        return attribute
68
69
 
 
70
    def coerce(self, value):
 
71
        return self._variable_class(**self._variable_kwargs).coerce(value)
 
72
 
69
73
 
70
74
class PropertyAttribute(Attribute):
71
75
 
89
93
        super(PropertyType, self).__init__(self.variable_class, kwargs)
90
94
 
91
95
 
 
96
class PropertyFactory(PropertyType):
 
97
 
 
98
    def __init__(self, type=None, **kwargs):
 
99
        if "default" in kwargs:
 
100
            raise ValueError("'default' not allowed for factories. "
 
101
                             "Use 'default_factory' instead.")
 
102
        if type is None:
 
103
            type = Property()
 
104
        kwargs["item_factory"] = VariableFactory(type._variable_class,
 
105
            **type._variable_kwargs)
 
106
        super(PropertyFactory, self).__init__(**kwargs)
 
107
 
 
108
 
 
109
class Constant(PropertyFactory):
 
110
 
 
111
    variable_class = ConstantVariable
 
112
 
 
113
 
92
114
class Bool(PropertyType):
93
115
 
94
116
    variable_class = BoolVariable
104
126
    variable_class = PathVariable
105
127
 
106
128
 
 
129
class Unicode(PropertyType):
 
130
 
 
131
    variable_class = UnicodeVariable
 
132
 
 
133
 
107
134
class Int(PropertyType):
108
135
 
109
136
    variable_class = IntVariable
114
141
    variable_class = FloatVariable
115
142
 
116
143
 
117
 
class List(PropertyType):
 
144
class List(PropertyFactory):
118
145
 
119
146
    variable_class = ListVariable
120
147
 
121
 
    def __init__(self, **kwargs):
122
 
        if "default" in kwargs:
123
 
            raise ValueError("'default' not allowed for List. "
124
 
                             "Use 'default_factory' instead.")
125
 
        type = kwargs.pop("type", None)
126
 
        if type is None:
127
 
            type = Property()
128
 
        kwargs["item_factory"] = VariableFactory(type._variable_class,
129
 
                                                 **type._variable_kwargs)
130
 
        super(List, self).__init__(**kwargs)
 
148
    def __init__(self, *args, **kwargs):
 
149
        kwargs["separator"] = kwargs.pop("separator", r"\s")
 
150
        super(List, self).__init__(*args, **kwargs)
 
151
 
 
152
 
 
153
class Tuple(PropertyFactory):
 
154
 
 
155
    variable_class = TupleVariable
 
156
 
 
157
 
 
158
class Any(PropertyType):
 
159
 
 
160
    variable_class = AnyVariable
 
161
 
 
162
    def __init__(self, schemas=[], **kwargs):
 
163
        kwargs["schemas"] = [VariableFactory(schema._variable_class,
 
164
            **schema._variable_kwargs) for schema in schemas]
 
165
        self.schemas = schemas
 
166
        super(Any, self).__init__(**kwargs)
 
167
 
 
168
 
 
169
class Dict(PropertyType):
 
170
 
 
171
    variable_class = DictVariable
 
172
 
 
173
    def __init__(self, key, value, **kwargs):
 
174
        kwargs["key_schema"] = VariableFactory(key._variable_class,
 
175
            **key._variable_kwargs)
 
176
        kwargs["value_schema"] = VariableFactory(value._variable_class,
 
177
            **value._variable_kwargs)
 
178
        super(Dict, self).__init__(**kwargs)
 
179
 
 
180
 
 
181
class Map(PropertyType):
 
182
 
 
183
    variable_class = MapVariable
 
184
 
 
185
    def __init__(self, schema={}, **kwargs):
 
186
        for key, type in schema.items():
 
187
            schema[key] = VariableFactory(type._variable_class,
 
188
                **type._variable_kwargs)
 
189
 
 
190
        kwargs["schema"] = schema
 
191
        super(Map, self).__init__(**kwargs)
 
192
 
 
193
 
 
194
class Message(Map):
 
195
 
 
196
    def __init__(self, type, schema={}, **kwargs):
 
197
        self.type = type
 
198
        schema["type"] = Constant(default_factory=lambda: type, type=String())
 
199
        super(Message, self).__init__(schema, **kwargs)