37 def get_children_for_reference(self, reference): |
39 def get_children_for_reference(self, reference): |
38 # implement ConE specific children expansion |
40 # implement ConE specific children expansion |
39 pass |
41 pass |
40 |
42 |
41 def handle_terminal(self, expression): |
43 def handle_terminal(self, expression): |
|
44 return self.data[expression] |
|
45 |
|
46 class TestPluginCondition(unittest.TestCase): |
|
47 |
|
48 def test_create_plugin_condition(self): |
|
49 condition = rules.SimpleCondition("${foo.bar}", "True") |
|
50 self.assertTrue(isinstance(condition.left, rules.ReferenceTerminal)) |
|
51 self.assertEquals(str(condition),'(${foo.bar} => None) == True') |
|
52 |
|
53 def test_create_plugin_and_eval_booleans(self): |
|
54 context = TestContext(None) |
|
55 condition = rules.SimpleCondition("1", "True") |
|
56 self.assertTrue(condition.eval(context)) |
|
57 condition = rules.SimpleCondition("0", True) |
|
58 self.assertFalse(condition.eval(context)) |
|
59 |
|
60 def test_create_plugin_and_eval_none(self): |
|
61 context = TestContext(None) |
|
62 condition = rules.SimpleCondition("None", "None") |
|
63 self.assertTrue(condition.eval(context)) |
|
64 condition = rules.SimpleCondition("None", None) |
|
65 self.assertTrue(condition.eval(context)) |
|
66 condition = rules.SimpleCondition(None, "None") |
|
67 self.assertTrue(condition.eval(context)) |
|
68 condition = rules.SimpleCondition(None, None) |
|
69 self.assertTrue(condition.eval(context)) |
|
70 |
|
71 condition = rules.SimpleCondition("True", None) |
|
72 self.assertFalse(condition.eval(context)) |
|
73 condition = rules.SimpleCondition(None, "True") |
|
74 self.assertFalse(condition.eval(context)) |
|
75 |
|
76 def test_create_plugin_and_eval_none_from_ref(self): |
|
77 context = TestContext({'Foo.Bar': None}) |
|
78 condition = rules.SimpleCondition("${Foo.Bar}", None) |
|
79 self.assertTrue(condition.eval(context)) |
|
80 |
|
81 def test_create_plugin_and_eval_unicode(self): |
|
82 context = TestContext({'Foo.Bar': u"foo\u20ac"}) |
|
83 condition = rules.SimpleCondition("${Foo.Bar}", u"foo\u20ac") |
|
84 self.assertTrue(condition.eval(context)) |
|
85 |
|
86 def test_create_plugin_and_eval_number_against_string(self): |
|
87 context = TestContext({'Foo.Int': 123, |
|
88 'Foo.Real': 123.4}) |
|
89 condition = rules.SimpleCondition("${Foo.Int}", "foo") |
|
90 self.assertFalse(condition.eval(context)) |
|
91 condition = rules.SimpleCondition("${Foo.Real}", "foo") |
|
92 self.assertFalse(condition.eval(context)) |
|
93 |
|
94 condition = rules.SimpleCondition("${Foo.Int}", "123") |
|
95 self.assertTrue(condition.eval(context)) |
|
96 condition = rules.SimpleCondition("${Foo.Real}", "123.4") |
|
97 self.assertTrue(condition.eval(context)) |
|
98 |
|
99 def xtest_selection_setting(self): |
|
100 conf = api.Configuration("test.confml", namespace="com.nokia.s60") |
|
101 |
|
102 context = TestContext(None) |
|
103 context.configuration = conf |
|
104 fea= api.Feature("foo") |
|
105 fea.add_feature(api.Feature("child1",type='selection')) |
|
106 fea.child1.create_option('one','1') |
|
107 fea.child1.create_option('two','2') |
|
108 |
|
109 conf.add_feature(fea) |
|
110 |
|
111 fea.child1.add_data(api.Data(value="2")) |
|
112 |
|
113 condition = rules.SimpleCondition("${fea.child1}", "2") |
|
114 self.assertTrue(condition.eval(context)) |
|
115 |
|
116 def test_sequence_setting(self): |
|
117 context = plugin.GenerationContext() |
|
118 context.configuration = api.Configuration() |
|
119 fea = model.ConfmlSequenceSetting("test") |
|
120 fea.add_feature(model.ConfmlIntSetting('child1')) |
|
121 fea.add_feature(model.ConfmlIntSetting('child2')) |
|
122 fea.add_feature(model.ConfmlIntSetting('child3')) |
|
123 context.configuration.add_feature(fea) |
|
124 seq = context.configuration.get_default_view().get_feature('test') |
|
125 seq.add_sequence(['1','2','3']) |
|
126 seq.add_sequence(['4','5','6']) |
|
127 seq.add_sequence(['7','8','9']) |
|
128 |
|
129 condition = rules.SimpleCondition("${test}", [[1,2,3], [4,5,6], [7,8,9]]) |
|
130 self.assertTrue(condition.eval(context)) |
|
131 |
|
132 condition = rules.SimpleCondition("${test}", [['11','22','33'], ['44','55','66'], ['77','88','99']]) |
|
133 self.assertFalse(condition.eval(context)) |
|
134 |
|
135 def test_boolean_setting(self): |
|
136 context = plugin.GenerationContext() |
|
137 context.configuration = api.Configuration() |
|
138 context.configuration.add_feature(model.ConfmlBooleanSetting("test")) |
|
139 |
|
140 context.configuration.get_default_view().test.value = True |
|
141 |
|
142 condition = rules.SimpleCondition("${test}", True) |
|
143 self.assertTrue(condition.eval(context)) |
|
144 |
|
145 condition = rules.SimpleCondition("${test}", "zoobar") |
|
146 self.assertFalse(condition.eval(context)) |
|
147 |
|
148 condition = rules.SimpleCondition("${test}", "1") |
|
149 self.assertFalse(condition.eval(context)) |
|
150 |
|
151 condition = rules.SimpleCondition("${test}", "true") |
|
152 self.assertTrue(condition.eval(context)) |
|
153 |
|
154 condition = rules.SimpleCondition("${test}", "0") |
|
155 self.assertFalse(condition.eval(context)) |
|
156 |
|
157 condition = rules.SimpleCondition("${test}", "") |
|
158 self.assertFalse(condition.eval(context)) |
|
159 |
|
160 condition = rules.SimpleCondition("${test}", None) |
|
161 self.assertFalse(condition.eval(context)) |
|
162 |
|
163 def test_string_setting(self): |
|
164 context = plugin.GenerationContext() |
|
165 context.configuration = api.Configuration() |
|
166 context.configuration.add_feature(model.ConfmlStringSetting("test")) |
|
167 |
|
168 context.configuration.get_default_view().test.value = "foobar" |
|
169 |
|
170 condition = rules.SimpleCondition("${test}", "foobar") |
|
171 self.assertTrue(condition.eval(context)) |
|
172 |
|
173 condition = rules.SimpleCondition("${test}", "zoobar") |
|
174 self.assertFalse(condition.eval(context)) |
|
175 |
|
176 condition = rules.SimpleCondition("${test}", "1") |
|
177 self.assertFalse(condition.eval(context)) |
|
178 |
|
179 condition = rules.SimpleCondition("${test}", "true") |
|
180 self.assertFalse(condition.eval(context)) |
|
181 |
|
182 condition = rules.SimpleCondition("${test}", "false") |
|
183 self.assertFalse(condition.eval(context)) |
|
184 |
|
185 condition = rules.SimpleCondition("${test}", "0") |
|
186 self.assertFalse(condition.eval(context)) |
|
187 |
|
188 condition = rules.SimpleCondition("${test}", "") |
|
189 self.assertFalse(condition.eval(context)) |
|
190 |
|
191 condition = rules.SimpleCondition("${test}", None) |
|
192 self.assertFalse(condition.eval(context)) |
|
193 |
|
194 def test_int_setting(self): |
|
195 context = plugin.GenerationContext() |
|
196 context.configuration = api.Configuration() |
|
197 context.configuration.add_feature(model.ConfmlIntSetting("test")) |
|
198 |
|
199 context.configuration.get_default_view().test.value = "1" |
|
200 |
|
201 condition = rules.SimpleCondition("${test}", "1") |
|
202 self.assertTrue(condition.eval(context)) |
|
203 |
|
204 condition = rules.SimpleCondition("${test}", 2) |
|
205 self.assertFalse(condition.eval(context)) |
|
206 |
|
207 condition = rules.SimpleCondition("${test}", True) |
|
208 self.assertTrue(condition.eval(context)) |
|
209 |
|
210 condition = rules.SimpleCondition("${test}", False) |
|
211 self.assertFalse(condition.eval(context)) |
|
212 |
|
213 condition = rules.SimpleCondition("${test}", 0) |
|
214 self.assertFalse(condition.eval(context)) |
|
215 |
|
216 condition = rules.SimpleCondition("${test}", "zoobar") |
42 try: |
217 try: |
43 m = re.match("\${(.*)}", expression) |
218 self.assertFalse(condition.eval(context)) |
44 if m: |
219 self.fail("Exception expected.") |
45 return self.data[m.group(1)] |
220 except Exception: |
46 elif expression in ['true','1','True']: |
221 pass |
47 return True |
222 |
48 elif expression in ['false','0','False']: |
223 condition = rules.SimpleCondition("${test}", "") |
49 return False |
224 try: |
50 else: |
225 self.assertFalse(condition.eval(context)) |
51 return eval(expression) |
226 self.fail("Exception expected.") |
52 except: |
227 except Exception: |
53 return expression |
228 pass |
54 |
229 |
55 class TestPluginCondition(unittest.TestCase): |
230 condition = rules.SimpleCondition("${test}", None) |
56 |
231 self.assertFalse(condition.eval(context)) |
57 def test_create_plugin_condition(self): |
232 |
58 condition = rules.SimpleCondition("foo.bar", "True") |
233 context.configuration.get_default_view().test.value = "-1" |
59 |
234 |
60 def test_create_plugin_and_eval_booleans(self): |
235 condition = rules.SimpleCondition("${test}", -1) |
61 context = TestContext(None) |
236 self.assertTrue(condition.eval(context)) |
62 condition = rules.SimpleCondition("1", "True") |
237 |
63 self.assertTrue(condition.eval(context)) |
238 condition = rules.SimpleCondition("${test}", 0) |
64 condition = rules.SimpleCondition("0", True) |
239 self.assertFalse(condition.eval(context)) |
65 self.assertFalse(condition.eval(context)) |
240 |
|
241 def test_selection_setting_true(self): |
|
242 context = plugin.GenerationContext() |
|
243 context.configuration = api.Configuration() |
|
244 context.configuration.add_feature(model.ConfmlSelectionSetting("test")) |
|
245 |
|
246 context.configuration.get_default_view().test.value = "True" |
|
247 |
|
248 condition = rules.SimpleCondition("${test}", "True") |
|
249 self.assertTrue(condition.eval(context)) |
|
250 |
|
251 condition = rules.SimpleCondition("${test}", True) |
|
252 self.assertTrue(condition.eval(context)) |
|
253 |
|
254 condition = rules.SimpleCondition("${test}", "1") |
|
255 self.assertFalse(condition.eval(context)) |
|
256 |
|
257 def test_selection_setting_false(self): |
|
258 context = plugin.GenerationContext() |
|
259 context.configuration = api.Configuration() |
|
260 context.configuration.add_feature(model.ConfmlSelectionSetting("test")) |
|
261 |
|
262 context.configuration.get_default_view().test.value = "False" |
|
263 |
|
264 condition = rules.SimpleCondition("${test}", False) |
|
265 self.assertTrue(condition.eval(context)) |
|
266 |
|
267 condition = rules.SimpleCondition("${test}", "False") |
|
268 self.assertTrue(condition.eval(context)) |
|
269 |
|
270 condition = rules.SimpleCondition("${test}", "0") |
|
271 self.assertFalse(condition.eval(context)) |
|
272 |
|
273 condition = rules.SimpleCondition("False", "0") |
|
274 self.assertFalse(condition.eval(context)) |
|
275 |
|
276 def test_selection_setting_int(self): |
|
277 context = plugin.GenerationContext() |
|
278 context.configuration = api.Configuration() |
|
279 context.configuration.add_feature(model.ConfmlSelectionSetting("test")) |
|
280 |
|
281 context.configuration.get_default_view().test.value = "2" |
|
282 |
|
283 condition = rules.SimpleCondition("${test}", "2") |
|
284 self.assertTrue(condition.eval(context)) |
|
285 |
|
286 condition = rules.SimpleCondition("${test}", 2) |
|
287 self.assertTrue(condition.eval(context)) |
66 |
288 |
67 def test_create_plugin_and_eval_integers(self): |
289 def test_create_plugin_and_eval_integers(self): |
68 context = TestContext(None) |
290 context = TestContext(None) |
69 condition = rules.SimpleCondition("1", "2") |
291 condition = rules.SimpleCondition("1", "2") |
70 self.assertFalse(condition.eval(context)) |
292 self.assertFalse(condition.eval(context)) |
71 condition = rules.SimpleCondition("112", "2") |
293 condition = rules.SimpleCondition("112", "2") |
72 self.assertFalse(condition.eval(context)) |
294 self.assertFalse(condition.eval(context)) |
73 condition = rules.SimpleCondition("2", "2") |
295 condition = rules.SimpleCondition("2", "2") |
74 self.assertTrue(condition.eval(context)) |
296 self.assertTrue(condition.eval(context)) |
|
297 condition = rules.SimpleCondition("2", 2) |
|
298 self.assertTrue(condition.eval(context)) |
75 condition = rules.SimpleCondition(2, 2) |
299 condition = rules.SimpleCondition(2, 2) |
|
300 self.assertTrue(condition.eval(context)) |
|
301 condition = rules.SimpleCondition("-2", -2) |
76 self.assertTrue(condition.eval(context)) |
302 self.assertTrue(condition.eval(context)) |
77 |
303 |
78 def test_create_plugin_and_eval_string(self): |
304 def test_create_plugin_and_eval_string(self): |
79 context = TestContext(None) |
305 context = TestContext(None) |
80 condition = plugin.rules.SimpleCondition("test", "foo") |
306 condition = plugin.rules.SimpleCondition("test", "foo") |