0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
3
|
15 |
#
|
0
|
16 |
|
|
17 |
"""
|
|
18 |
Test the configuration
|
|
19 |
"""
|
|
20 |
import unittest
|
3
|
21 |
import os
|
|
22 |
import pickle
|
0
|
23 |
|
3
|
24 |
from cone.public import api,exceptions
|
0
|
25 |
from cone.storage import persistentdictionary
|
3
|
26 |
from testautomation.utils import remove_if_exists
|
|
27 |
|
|
28 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
0
|
29 |
|
|
30 |
class TestConfiguration(unittest.TestCase):
|
|
31 |
def setUp(self):
|
|
32 |
pass
|
|
33 |
|
|
34 |
# @test
|
|
35 |
def test_create_configuration(self):
|
|
36 |
conf = api.Configuration("testmee.confml")
|
|
37 |
self.assertTrue(conf)
|
|
38 |
|
3
|
39 |
def test_configuration_reduce_ex(self):
|
|
40 |
prj = api.Project(api.Storage('.'))
|
|
41 |
conf = api.Configuration("testmee.confml")
|
|
42 |
prj.add_configuration(conf)
|
|
43 |
tpl = conf.__reduce_ex__(2)
|
|
44 |
self.assertEquals(tpl[2]['_storeint'],prj)
|
|
45 |
self.assertEquals(tpl[2]['path'],'testmee.confml')
|
|
46 |
|
|
47 |
def test_configuration_pickle(self):
|
|
48 |
remove_if_exists(os.path.join(ROOT_PATH,'temp'))
|
|
49 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'temp'), 'w'))
|
|
50 |
conf = api.Configuration("testmee.confml")
|
|
51 |
prj.add_configuration(conf, True)
|
|
52 |
prj.save()
|
|
53 |
dfile = open(os.path.join(ROOT_PATH,'temp/out.dat'), 'w')
|
|
54 |
pickle.dump(conf, dfile)
|
|
55 |
dfile.close()
|
|
56 |
dfile = open(os.path.join(ROOT_PATH,'temp/out.dat'))
|
|
57 |
conf2 = pickle.load(dfile)
|
|
58 |
self.assertEquals(conf2.path,'testmee.confml')
|
|
59 |
self.assertEquals(conf2.name,'testmee_confml')
|
|
60 |
|
|
61 |
|
0
|
62 |
def test_get_root_configuration(self):
|
|
63 |
conf = api.Configuration("testmee.confml")
|
|
64 |
self.assertEquals(conf.get_root_configuration(),conf)
|
|
65 |
conf.add_configuration(api.Configuration("foo/foo.confml"))
|
|
66 |
conf.add_configuration(api.Configuration("fii/fii.confml"))
|
|
67 |
conf.fii__fii_confml.add_configuration(api.Configuration("fii/foo.confml"))
|
|
68 |
self.assertEquals(conf.fii__fii_confml.get_root_configuration(),conf)
|
|
69 |
self.assertEquals(conf.foo__foo_confml.get_root_configuration(),conf)
|
|
70 |
self.assertEquals(conf.fii__fii_confml.fii__foo_confml.get_root_configuration(),conf)
|
|
71 |
|
|
72 |
def test_get_last_configuration(self):
|
|
73 |
conf = api.Configuration("testmee.confml")
|
|
74 |
conf.add_configuration(api.Configuration("foo/foo.confml"))
|
|
75 |
conf.add_configuration(api.Configuration("fii/fii.confml"))
|
|
76 |
conf.add_configuration(api.Configuration("hii/hii.confml"))
|
|
77 |
conf.fii__fii_confml.add_configuration(api.Configuration("fii/foo.confml"))
|
|
78 |
self.assertEquals(conf.list_configurations(), ["foo/foo.confml","fii/fii.confml","hii/hii.confml"])
|
|
79 |
|
|
80 |
self.assertEquals(conf.get_configuration_by_index(-1).get_path(), "hii/hii.confml")
|
|
81 |
self.assertEquals(conf.get_configuration_by_index(0).get_path(), "foo/foo.confml")
|
|
82 |
self.assertEquals(conf.get_configuration_by_index(1).get_path(), "fii/fii.confml")
|
|
83 |
self.assertEquals(conf.get_configuration_by_index(2).get_path(), "hii/hii.confml")
|
|
84 |
|
|
85 |
def compareconfiguration(self, conf1,conf2):
|
|
86 |
self.assertEquals(conf1.path,conf2.path)
|
|
87 |
self.assertEquals(conf1.name,conf2.name)
|
|
88 |
self.assertEquals(conf1.ref,conf2.ref)
|
|
89 |
self.assertEquals(conf1.namespace,conf2.namespace)
|
|
90 |
|
3
|
91 |
def test_get_configuration_and_path(self):
|
|
92 |
conf1 = api.Configuration("testmee.confml")
|
|
93 |
fea = conf1.create_feature('test1')
|
|
94 |
conf1.create_feature('test2')
|
|
95 |
subfea = fea.create_feature('child1')
|
|
96 |
self.assertEquals(fea.get_configuration(), conf1)
|
|
97 |
self.assertEquals(fea.get_configuration_path(), 'testmee.confml')
|
|
98 |
self.assertEquals(subfea.get_configuration(), conf1)
|
|
99 |
self.assertEquals(subfea.get_configuration_path(), 'testmee.confml')
|
|
100 |
|
0
|
101 |
def test_clone_single_configuration(self):
|
|
102 |
conf1 = api.Configuration("testmee.confml")
|
|
103 |
conf1.add_feature(api.Feature('test1'))
|
|
104 |
conf1.add_feature(api.Feature('test2'))
|
|
105 |
conf1.add_feature(api.Feature('child1'),'test1')
|
|
106 |
dview = conf1.get_default_view()
|
|
107 |
dview.get_feature('test1').set_value('one')
|
|
108 |
dview.get_feature('test1.child1').set_value('subone')
|
|
109 |
conf2 = conf1._clone(recursion=True)
|
|
110 |
self.compareconfiguration(conf1, conf2)
|
|
111 |
self.assertEquals(conf2.list_all_features(),['test1', 'test1.child1', 'test2'])
|
|
112 |
dview2 = conf2.get_default_view()
|
|
113 |
self.assertEquals(dview2.get_feature('test1').get_value(),'one')
|
|
114 |
self.assertEquals(dview2.get_feature('test1.child1').get_value(),'subone')
|
|
115 |
|
|
116 |
def test_clone_configuration_with_includes(self):
|
|
117 |
conf1 = api.Configuration("testmee.confml")
|
|
118 |
conf1.add_feature(api.Feature('test1'))
|
|
119 |
conf1.add_feature(api.Feature('test2'))
|
|
120 |
conf1.add_feature(api.Feature('child1'),'test1')
|
|
121 |
conf1.create_configuration("confml/data.confml")
|
|
122 |
dview = conf1.get_default_view()
|
|
123 |
dview.get_feature('test1').set_value('one')
|
|
124 |
dview.get_feature('test1.child1').set_value('subone')
|
|
125 |
conf2 = conf1._clone(recursion=True)
|
|
126 |
self.compareconfiguration(conf1, conf2)
|
|
127 |
self.assertEquals(conf2.list_all_features(),['test1', 'test1.child1', 'test2'])
|
|
128 |
self.assertEquals(conf2.list_configurations(),['confml/data.confml'])
|
|
129 |
dview2 = conf2.get_default_view()
|
|
130 |
self.assertEquals(dview2.get_feature('test1').get_value(),'one')
|
|
131 |
self.assertEquals(dview2.get_feature('test1.child1').get_value(),'subone')
|
|
132 |
|
|
133 |
# def test_create_and_get_root(self):
|
|
134 |
# conf = api.Configuration("foobar/testmee.confml")
|
|
135 |
# self.assertEquals(conf.get_root(),"foobar/testmee.confml")
|
|
136 |
|
|
137 |
class TestCompositeConfiguration(unittest.TestCase):
|
|
138 |
def test_add(self):
|
|
139 |
conf = api.Configuration("data/simple.confml")
|
|
140 |
layer = api.Configuration("laa")
|
3
|
141 |
conf.add_configuration(layer)
|
0
|
142 |
self.assertEquals(conf.list_configurations()[0],"laa")
|
|
143 |
|
|
144 |
def test_add_and_access_via_member(self):
|
|
145 |
conf = api.Configuration("data/simple.confml")
|
|
146 |
layer = api.Configuration("laa")
|
3
|
147 |
conf.add_configuration(layer)
|
|
148 |
self.assertEquals(conf.laa.name,"laa")
|
0
|
149 |
|
|
150 |
def test_add_and_add_another_config_under(self):
|
|
151 |
conf = api.Configuration("data/simple.confml")
|
|
152 |
layer = api.Configuration("laa")
|
3
|
153 |
conf.add_configuration(layer)
|
|
154 |
conf.laa.add_configuration(api.Configuration("foo"))
|
|
155 |
self.assertEquals(conf.laa.foo.name,"foo")
|
0
|
156 |
|
|
157 |
def test_add_several_configurations(self):
|
|
158 |
conf = api.Configuration("data/simple.confml")
|
|
159 |
layer = api.Configuration("laa")
|
3
|
160 |
conf.add_configuration(layer)
|
|
161 |
conf.add_configuration(api.Configuration("foo"))
|
|
162 |
conf.add_configuration(api.Configuration("faa"))
|
0
|
163 |
self.assertEquals(conf.list_configurations()[0],"laa")
|
|
164 |
self.assertEquals(conf.list_configurations()[1],"foo")
|
|
165 |
self.assertEquals(conf.list_configurations()[2],"faa")
|
|
166 |
|
|
167 |
def test_add_several_and_remove_one_layer(self):
|
|
168 |
conf = api.Configuration("data/simple.confml")
|
|
169 |
layer = api.Configuration("laa")
|
3
|
170 |
conf.add_configuration(layer)
|
|
171 |
conf.add_configuration(api.Configuration("foo"))
|
|
172 |
conf.add_configuration(api.Configuration("faa"))
|
|
173 |
conf.remove_configuration("foo")
|
0
|
174 |
|
|
175 |
self.assertEquals(conf.list_configurations()[0],"laa")
|
|
176 |
self.assertEquals(conf.list_configurations()[1],"faa")
|
|
177 |
|
|
178 |
def test_add_several_and_remove_last_layer(self):
|
|
179 |
conf = api.Configuration("data/simple.confml")
|
|
180 |
layer = api.Configuration("laa")
|
3
|
181 |
conf.add_configuration(layer)
|
|
182 |
conf.add_configuration(api.Configuration("foo"))
|
|
183 |
conf.add_configuration(api.Configuration("faa"))
|
|
184 |
conf.remove_configuration("faa")
|
0
|
185 |
self.assertEquals(conf.list_configurations()[0],"laa")
|
|
186 |
self.assertEquals(conf.list_configurations()[1],"foo")
|
|
187 |
|
|
188 |
def test_add_several_and_remove_all_configurations(self):
|
|
189 |
conf = api.Configuration("data/simple.confml")
|
|
190 |
layer = api.Configuration("laa")
|
3
|
191 |
conf.add_configuration(layer)
|
|
192 |
conf.add_configuration(api.Configuration("foo"))
|
|
193 |
conf.add_configuration(api.Configuration("faa"))
|
0
|
194 |
for layername in conf.list_configurations():
|
3
|
195 |
conf.remove_configuration(layername)
|
0
|
196 |
|
|
197 |
self.assertTrue(len(conf.list_configurations())==0)
|
|
198 |
|
|
199 |
def test_add_several_and_try_to_remove_not_existing(self):
|
|
200 |
conf = api.Configuration("data/simple.confml")
|
|
201 |
layer = api.Configuration("laa")
|
3
|
202 |
conf.add_configuration(layer)
|
|
203 |
conf.add_configuration(api.Configuration("foo"))
|
|
204 |
conf.add_configuration(api.Configuration("faa"))
|
0
|
205 |
try:
|
3
|
206 |
conf.remove_configuration("notthere")
|
0
|
207 |
self.fail("removing of nonexisting layer succeeds!")
|
|
208 |
except exceptions.NotFound:
|
|
209 |
pass
|
|
210 |
|
3
|
211 |
def test_create_view_simple(self):
|
0
|
212 |
conf = api.Configuration("data/simple.confml")
|
3
|
213 |
conf.create_view("view1")
|
0
|
214 |
view = conf.get_view("view1")
|
3
|
215 |
self.assertEquals(view.list_groups(),[])
|
0
|
216 |
|
3
|
217 |
def test_create_views_and_list_views(self):
|
0
|
218 |
conf = api.Configuration("data/simple.confml")
|
3
|
219 |
conf.create_view("view1")
|
|
220 |
conf.create_view("view2")
|
0
|
221 |
self.assertEquals(conf.list_views(),['view1','view2'])
|
|
222 |
|
3
|
223 |
def test_create_views_and_remove_one(self):
|
0
|
224 |
conf = api.Configuration("data/simple.confml")
|
3
|
225 |
conf.create_view("view1")
|
|
226 |
conf.create_view("view2")
|
|
227 |
conf.create_view("view3")
|
0
|
228 |
conf.remove_view('view2')
|
|
229 |
self.assertEquals(conf.list_views(),['view1','view3'])
|
|
230 |
|
3
|
231 |
def test_create_views_and_remove_invalid(self):
|
0
|
232 |
conf = api.Configuration("data/simple.confml")
|
3
|
233 |
conf.create_view("view1")
|
|
234 |
conf.create_view("view2")
|
|
235 |
conf.create_view("view3")
|
0
|
236 |
try:
|
|
237 |
conf.remove_view('invalid')
|
|
238 |
self.fail('Removing invalid view succeeds!')
|
|
239 |
except exceptions.NotFound:
|
|
240 |
pass
|
|
241 |
|
3
|
242 |
def test_create_views_and_remove_all(self):
|
0
|
243 |
conf = api.Configuration("data/simple.confml")
|
3
|
244 |
conf.create_view("view1")
|
|
245 |
conf.create_view("view2")
|
|
246 |
conf.create_view("view3")
|
0
|
247 |
for view in conf.list_views():
|
|
248 |
conf.remove_view(view)
|
|
249 |
self.assertEquals(conf.list_views(),[])
|
|
250 |
|
3
|
251 |
def test_create_view_with_data(self):
|
0
|
252 |
conf = api.Configuration("data/simple.confml")
|
3
|
253 |
conf.create_view("view1")
|
0
|
254 |
view = conf.get_view("view1")
|
3
|
255 |
view.add_group(api.Group("group1"))
|
|
256 |
view.add_group(api.Group("group2"))
|
|
257 |
view.create_featurelink("feature1")
|
|
258 |
view.group1.add_group(api.Group("group21"))
|
|
259 |
view.group1.group21.create_featurelink("feature211")
|
|
260 |
view.group1.group21.create_featurelink("feature212")
|
0
|
261 |
|
|
262 |
self.assertEquals(sorted(view._list_traverse()),
|
|
263 |
sorted(['group1',
|
3
|
264 |
'group1.group21',
|
|
265 |
'group1.group21.link_feature211',
|
|
266 |
'group1.group21.link_feature212',
|
|
267 |
'group2',
|
|
268 |
'link_feature1']))
|
0
|
269 |
|
|
270 |
def test_get_default_view(self):
|
|
271 |
conf = api.Configuration("data/simple.confml")
|
|
272 |
dview = conf.get_default_view()
|
3
|
273 |
self.assertEquals(dview.ref,'?default_view')
|
|
274 |
|
|
275 |
def test_create_configuration_and_features(self):
|
|
276 |
conf = api.Configuration("data/simple.confml")
|
|
277 |
fea = conf.create_feature("test")
|
|
278 |
self.assertEquals(conf.get_feature('test'), fea)
|
|
279 |
fea = conf.create_feature("test1", name="test name")
|
|
280 |
self.assertEquals(conf.get_feature('test1').name, 'test name')
|
|
281 |
fea.create_feature("subfea", name="subfea name")
|
|
282 |
self.assertEquals(conf.list_all_features(), ['test','test1','test1.subfea'])
|
0
|
283 |
|
|
284 |
def test_get_default_view_and_data_to_it(self):
|
|
285 |
conf = api.Configuration("data/simple.confml")
|
|
286 |
view = conf.get_default_view()
|
|
287 |
view._add(api.Group("group1"))
|
|
288 |
view._add(api.Group("group2"))
|
|
289 |
view._add(api._FeatureProxy("feature1"))
|
|
290 |
view.group1._add(api.Group("group21"))
|
|
291 |
view.group1.group21._add(api._FeatureProxy("feature211"))
|
|
292 |
view.group1.group21._add(api._FeatureProxy("feature212"))
|
|
293 |
view.feature1._add(api._FeatureProxy("feature11"))
|
|
294 |
|
|
295 |
self.assertEquals(sorted(view._list_traverse()),
|
|
296 |
sorted(['group1',
|
|
297 |
'group2',
|
|
298 |
'feature1',
|
|
299 |
'group1.group21',
|
|
300 |
'group1.group21.feature211',
|
|
301 |
'group1.group21.feature212',
|
|
302 |
'feature1.feature11']))
|
|
303 |
|
|
304 |
|
|
305 |
def test_add_feature_normal_configuration(self):
|
|
306 |
conf = api.Configuration("simple.confml")
|
|
307 |
conf.add_feature(api.Feature("feature1"))
|
|
308 |
self.assertEquals(conf.list_all_features(),['feature1'])
|
|
309 |
|
|
310 |
def test_add_feature_normal_and_get_default_view(self):
|
|
311 |
conf = api.Configuration("simple.confml")
|
|
312 |
conf.add_feature(api.Feature("feature1"))
|
|
313 |
conf.add_feature(api.Feature("feature2"))
|
|
314 |
conf.add_feature(api.Feature("feature11"),'feature1')
|
|
315 |
view = conf.get_default_view()
|
|
316 |
|
|
317 |
self.assertEquals(view.list_all_features(),['feature1',
|
|
318 |
'feature1.feature11',
|
|
319 |
'feature2',])
|
|
320 |
self.assertEquals(view.get_feature('feature1.feature11')._obj._parent,conf.feature1)
|
|
321 |
|
|
322 |
def test_add_feature_hierarchy_and_get_default_view(self):
|
|
323 |
root = api.Configuration("data/simple.confml")
|
|
324 |
conf = api.Configuration("test/root.confml")
|
|
325 |
root.add_configuration(conf)
|
|
326 |
conf2 = api.Configuration("test2/root.confml",namespace="com.nokia")
|
|
327 |
root.add_configuration(conf2)
|
|
328 |
conf.add_feature(api.Feature("group1"))
|
|
329 |
conf.add_feature(api.Feature("group2"))
|
|
330 |
conf.add_feature(api.Feature("feature1"))
|
|
331 |
conf.group1.add_feature(api.Feature("group21"))
|
|
332 |
conf.group1.group21.add_feature(api.Feature("feature211"))
|
|
333 |
conf.group1.group21.add_feature(api.Feature("feature212"))
|
|
334 |
conf.feature1.add_feature(api.Feature("feature11"))
|
|
335 |
conf2.add_feature(api.Feature("wlan"))
|
|
336 |
conf2.add_feature(api.Feature("bluetooth"))
|
|
337 |
self.assertEquals(conf.list_all_features(),
|
|
338 |
['group1',
|
|
339 |
'group1.group21',
|
|
340 |
'group1.group21.feature211',
|
|
341 |
'group1.group21.feature212',
|
|
342 |
'group2',
|
|
343 |
'feature1',
|
|
344 |
'feature1.feature11'])
|
|
345 |
dview = conf.get_default_view()
|
|
346 |
self.assertEquals(dview.list_features(),
|
|
347 |
['group1',
|
|
348 |
'group2',
|
|
349 |
'feature1'])
|
|
350 |
|
|
351 |
self.assertEquals(dview.list_groups(),['com'])
|
|
352 |
self.assertEquals(dview.list_all_features(),
|
|
353 |
['group1',
|
|
354 |
'group1.group21',
|
|
355 |
'group1.group21.feature211',
|
|
356 |
'group1.group21.feature212',
|
|
357 |
'group2',
|
|
358 |
'feature1',
|
|
359 |
'feature1.feature11',
|
|
360 |
'com.nokia.wlan',
|
|
361 |
'com.nokia.bluetooth'])
|
|
362 |
|
|
363 |
def test_add_feature(self):
|
|
364 |
conf = api.Configuration("simple.confml")
|
|
365 |
conf.add_feature(api.Feature("feature1"))
|
|
366 |
self.assertEquals(conf.list_features(),['feature1'])
|
|
367 |
|
|
368 |
# def test_add_feature_namespace(self):
|
|
369 |
# conf = api.Configuration("test","com.nokia")
|
|
370 |
# conf.add_feature(api.Feature("feature1"))
|
|
371 |
# self.assertEquals(conf.list_all_features(),['com.nokia.feature1'])
|
|
372 |
# self.assertEquals(conf.feature1, conf.get_default_view().com.nokia.feature1._obj)
|
3
|
373 |
def test_get_path_for_parent(self):
|
|
374 |
conf = api.Configuration("test.confml")
|
|
375 |
conf.create_configuration("foo/root.confml")
|
|
376 |
conf.get_configuration("foo/root.confml").create_configuration("confml/jee.confml")
|
|
377 |
self.assertEquals(conf.get_path_for_parent(None), "test.confml")
|
|
378 |
self.assertEquals(conf.get_configuration("foo/root.confml").get_path_for_parent(None), "foo/root.confml")
|
|
379 |
foo = conf.get_configuration("foo/root.confml")
|
|
380 |
jee = foo.get_configuration("confml/jee.confml")
|
|
381 |
self.assertEquals(foo.get_path_for_parent(conf), "foo/root.confml")
|
|
382 |
self.assertEquals(jee.get_path_for_parent(conf), "foo/confml/jee.confml")
|
|
383 |
self.assertEquals(jee.get_path_for_parent(foo._obj), "confml/jee.confml")
|
|
384 |
|
0
|
385 |
|
|
386 |
def test_add_subconfiguration(self):
|
|
387 |
conf = api.Configuration("test",namespace="com.nokia")
|
|
388 |
conf.create_configuration("foo/root.confml")
|
|
389 |
conf.create_configuration("platforms/s60.confml")
|
3
|
390 |
dconf = api.Configuration('confml/data.confml')
|
|
391 |
sconf = conf.get_configuration('foo/root.confml')
|
|
392 |
sconf.add_configuration(dconf)
|
0
|
393 |
self.assertEquals(conf.list_configurations(),['foo/root.confml',
|
|
394 |
'platforms/s60.confml',])
|
3
|
395 |
self.assertEquals(conf.list_all_configurations(),['foo/root.confml',
|
|
396 |
'foo/confml/data.confml',
|
|
397 |
'platforms/s60.confml'])
|
|
398 |
self.assertEquals(conf.get_configuration('foo/root.confml').list_all_configurations(),['confml/data.confml'])
|
|
399 |
|
|
400 |
|
0
|
401 |
def test_remove_configuration(self):
|
|
402 |
conf = api.Configuration("test.confml",namespace="com.nokia")
|
|
403 |
conf.create_configuration("foo/root.confml")
|
|
404 |
self.assertEquals(conf.list_configurations(),['foo/root.confml'])
|
|
405 |
conf.remove_configuration("foo/root.confml")
|
|
406 |
self.assertEquals(conf.list_configurations(),[])
|
|
407 |
|
|
408 |
def test_get_configuration(self):
|
|
409 |
conf = api.Configuration("test.confml",namespace="com.nokia")
|
|
410 |
conf.create_configuration("foo/root.confml")
|
|
411 |
self.assertEquals(conf.list_configurations(),['foo/root.confml'])
|
|
412 |
foo = conf.get_configuration("foo/root.confml")
|
|
413 |
self.assertEquals(foo.get_path(),"foo/root.confml")
|
|
414 |
|
|
415 |
|
|
416 |
def test_remove_all(self):
|
|
417 |
conf = api.Configuration("test",namespace="com.nokia")
|
|
418 |
conf.create_configuration("foo/root.confml")
|
|
419 |
conf.create_configuration("platforms/s60.confml")
|
|
420 |
conf.create_configuration("platforms/customsw.confml")
|
|
421 |
self.assertEquals(conf.list_configurations(),['foo/root.confml',
|
|
422 |
'platforms/s60.confml',
|
|
423 |
'platforms/customsw.confml'])
|
|
424 |
for configref in conf.list_configurations():
|
|
425 |
conf.remove_configuration(configref)
|
|
426 |
self.assertEquals(conf.list_configurations(),[])
|
|
427 |
|
|
428 |
|
|
429 |
def test_add_subconfiguration_and_access(self):
|
|
430 |
conf = api.Configuration("data/simple.confml")
|
|
431 |
conf.create_configuration("foo/layer1.confml")
|
|
432 |
self.assertTrue(conf.foo__layer1_confml)
|
|
433 |
|
|
434 |
# def test_add_subconfiguration_and_features(self):
|
|
435 |
# conf = api.Configuration("test","com.nokia")
|
|
436 |
# conf.create_configuration("foo/root.confml")
|
|
437 |
# conf.create_configuration("fii/root.confml")
|
|
438 |
# conf.foo_root.add_feature(api.Feature("feature1"))
|
|
439 |
# conf.foo_root.add_feature(api.Feature("feature12"),"feature1")
|
|
440 |
# conf.fii_root.add_feature(api.Feature("feature2"))
|
|
441 |
# conf.fii_root.add_feature(api.Feature("feature21"),"feature2")
|
|
442 |
# self.assertEquals(conf.list_all_features(),['com.nokia.feature1',
|
|
443 |
# 'com.nokia.feature1.feature12',
|
|
444 |
# 'com.nokia.feature2',
|
|
445 |
# 'com.nokia.feature2.feature21',
|
|
446 |
# ])
|
|
447 |
# self.assertEquals(conf.foo_root.feature1.get_ref(),
|
|
448 |
# conf.get_default_view()._get('com.nokia.feature1').get_ref())
|
|
449 |
|
|
450 |
def test_add_configuration_with_features_to_root(self):
|
|
451 |
root= api.Configuration("test",namespace="com.nokia")
|
|
452 |
conf1 = api.Configuration("foo/foo.confml")
|
|
453 |
conf1.add_feature(api.Feature("feature1"))
|
|
454 |
conf1.add_feature(api.Feature("feature12"),"feature1")
|
|
455 |
conf2 = api.Configuration("bar/bar.confml")
|
|
456 |
conf2.add_feature(api.Feature("feature2"))
|
|
457 |
conf2.add_feature(api.Feature("feature22"),"feature2")
|
|
458 |
root.add_configuration(conf1)
|
|
459 |
self.assertEquals(root.list_all_features(),
|
|
460 |
['feature1',
|
|
461 |
'feature1.feature12'])
|
|
462 |
root.add_configuration(conf2)
|
|
463 |
self.assertEquals(root.list_all_features(),
|
|
464 |
['feature1',
|
|
465 |
'feature1.feature12',
|
|
466 |
'feature2',
|
|
467 |
'feature2.feature22'])
|
|
468 |
|
|
469 |
def test_add_configuration_to_other_conf_and_then_to_root(self):
|
|
470 |
root= api.Configuration("test",namespace="com.nokia")
|
|
471 |
conf1 = api.Configuration("foo/foo.confml")
|
|
472 |
conf1.add_feature(api.Feature("feature1"))
|
|
473 |
conf1.add_feature(api.Feature("feature12"),"feature1")
|
|
474 |
conf2 = api.Configuration("bar/foo.confml")
|
|
475 |
conf2.add_feature(api.Feature("feature2"))
|
|
476 |
conf2.add_feature(api.Feature("feature22"),"feature2")
|
|
477 |
conf2.add_configuration(conf1)
|
|
478 |
self.assertEquals(conf2.list_all_features(),
|
|
479 |
['feature2',
|
|
480 |
'feature2.feature22',
|
|
481 |
'feature1',
|
|
482 |
'feature1.feature12'])
|
|
483 |
root.add_configuration(conf2)
|
|
484 |
self.assertEquals(root.list_all_features(),
|
|
485 |
['feature2',
|
|
486 |
'feature2.feature22',
|
|
487 |
'feature1',
|
|
488 |
'feature1.feature12'])
|
|
489 |
|
|
490 |
def test_add_features_feature_hiararchy_and_then_to_configurations(self):
|
|
491 |
conf1 = api.Configuration("foo/foo.confml")
|
|
492 |
fea = api.Feature('feature1')
|
|
493 |
fea2 = api.Feature('feature12')
|
|
494 |
fea2.add_feature(api.Feature('feature121'))
|
|
495 |
fea.add_feature(api.Feature('feature11'))
|
|
496 |
fea.add_feature(fea2)
|
|
497 |
self.assertEquals(fea.list_all_features(),
|
|
498 |
['feature11',
|
|
499 |
'feature12',
|
|
500 |
'feature12.feature121'])
|
|
501 |
conf1.add_feature(fea)
|
|
502 |
self.assertEquals(conf1.list_all_features(),
|
|
503 |
['feature1',
|
|
504 |
'feature1.feature11',
|
|
505 |
'feature1.feature12',
|
|
506 |
'feature1.feature12.feature121'])
|
|
507 |
|
|
508 |
|
|
509 |
def test_add_features_and_remove_one(self):
|
|
510 |
conf1 = api.Configuration("foo/foo.confml")
|
|
511 |
fea = api.Feature('feature1')
|
|
512 |
fea2 = api.Feature('feature12')
|
|
513 |
fea2.add_feature(api.Feature('feature121'))
|
|
514 |
fea.add_feature(api.Feature('feature11'))
|
|
515 |
fea.add_feature(fea2)
|
|
516 |
conf1.add_feature(fea)
|
|
517 |
conf1.remove_feature('feature1.feature12')
|
|
518 |
self.assertEquals(conf1.list_all_features(),
|
|
519 |
['feature1',
|
|
520 |
'feature1.feature11'])
|
|
521 |
fea.remove_feature('feature11')
|
|
522 |
self.assertEquals(conf1.list_all_features(),
|
|
523 |
['feature1'])
|
|
524 |
|
|
525 |
def test_add_features_and_remove_all(self):
|
|
526 |
conf = api.Configuration("foo/foo.confml")
|
|
527 |
fea = api.Feature('feature1')
|
|
528 |
conf.add_feature(fea)
|
|
529 |
conf.add_feature(api.Feature('feature2'))
|
|
530 |
conf.add_feature(api.Feature('feature3'))
|
|
531 |
conf.add_feature(api.Feature('feature4'))
|
|
532 |
for fearef in conf.list_features():
|
|
533 |
conf.remove_feature(fearef)
|
|
534 |
self.assertEquals(conf.list_all_features(), [])
|
|
535 |
|
|
536 |
def test_add_features_and_create_view(self):
|
|
537 |
|
|
538 |
conf = api.Configuration("foo/foo.confml")
|
|
539 |
conf.add_feature(api.Feature('feature1'))
|
|
540 |
conf.add_feature(api.Feature('feature2'))
|
|
541 |
conf.add_feature(api.Feature('feature3'))
|
|
542 |
conf.add_feature(api.Feature('feature4'))
|
|
543 |
conf.add_feature(api.Feature('feature11'),'feature1')
|
|
544 |
conf.add_feature(api.Feature('feature12'),'feature1')
|
|
545 |
|
3
|
546 |
conf.create_view("rootfeas")
|
0
|
547 |
view = conf.get_view('rootfeas')
|
|
548 |
for fearef in conf.list_features():
|
|
549 |
fea = conf.get_feature(fearef)
|
|
550 |
view.add_feature(fea)
|
|
551 |
self.assertEquals(view.list_all_features(), ['feature1',
|
|
552 |
'feature2',
|
|
553 |
'feature3',
|
|
554 |
'feature4'])
|
|
555 |
view.remove_feature('feature2')
|
|
556 |
self.assertEquals(view.list_all_features(), ['feature1',
|
|
557 |
'feature3',
|
|
558 |
'feature4'])
|
|
559 |
|
|
560 |
def test_add_features_and_create_view_with_links(self):
|
|
561 |
conf = api.Configuration("foo/foo.confml")
|
|
562 |
conf.add_feature(api.Feature('feature1'))
|
|
563 |
conf.add_feature(api.Feature('feature2'))
|
|
564 |
conf.add_feature(api.Feature('feature3'))
|
|
565 |
conf.add_feature(api.Feature('feature4'))
|
|
566 |
conf.add_feature(api.Feature('feature11'),'feature1')
|
|
567 |
conf.add_feature(api.Feature('feature12'),'feature1')
|
3
|
568 |
conf.create_view('fea1')
|
0
|
569 |
view1 = conf.get_view('fea1')
|
3
|
570 |
view1.create_group('thegruppe1')
|
0
|
571 |
view1.get_group('thegruppe1').add(api.FeatureLink('feature1.feature11'))
|
|
572 |
view1.add(api.FeatureLink('feature1.*'))
|
|
573 |
view1.populate()
|
3
|
574 |
self.assertEquals(view1.list_all_features(),
|
|
575 |
['thegruppe1.proxy_feature1_feature11',
|
|
576 |
'proxy_feature1_feature11',
|
|
577 |
'proxy_feature1_feature12'])
|
|
578 |
fpr = view1.get_feature('thegruppe1.proxy_feature1_feature11')
|
0
|
579 |
self.assertEquals(fpr._obj.fqr,conf.get_default_view().get_feature('feature1.feature11').fqr)
|
3
|
580 |
self.assertEquals(view1.list_all_features(),
|
|
581 |
['thegruppe1.proxy_feature1_feature11',
|
|
582 |
'proxy_feature1_feature11',
|
|
583 |
'proxy_feature1_feature12'])
|
0
|
584 |
|
|
585 |
def test_add_features_and_create_all_view_with_links(self):
|
|
586 |
conf = api.Configuration("foo/foo.confml")
|
|
587 |
conf.add_feature(api.Feature('feature1'))
|
|
588 |
conf.add_feature(api.Feature('feature2'))
|
|
589 |
conf.add_feature(api.Feature('feature3'))
|
|
590 |
conf.add_feature(api.Feature('feature4'))
|
|
591 |
conf.add_feature(api.Feature('feature11'),'feature1')
|
|
592 |
conf.add_feature(api.Feature('feature12'),'feature1')
|
3
|
593 |
conf.create_view("all")
|
0
|
594 |
view1 = conf.get_view('all')
|
|
595 |
view1.add(api.FeatureLink('**'))
|
|
596 |
view1.populate()
|
3
|
597 |
self.assertEquals(view1.list_all_features(),
|
|
598 |
['proxy_feature1',
|
|
599 |
'proxy_feature1_feature11',
|
|
600 |
'proxy_feature1_feature12',
|
|
601 |
'proxy_feature2',
|
|
602 |
'proxy_feature3',
|
|
603 |
'proxy_feature4'])
|
|
604 |
fpr = view1.get_feature('proxy_feature1_feature11')
|
0
|
605 |
self.assertEquals(fpr._obj.fqr,conf.get_default_view().get_feature('feature1.feature11').fqr)
|
|
606 |
|
|
607 |
def test_add_a_configuration_and_remove_it(self):
|
|
608 |
conf = api.Configuration("simple.confml")
|
|
609 |
conf.add_configuration(api.Configuration("confml/data.confml"))
|
|
610 |
self.assertEquals(conf.list_configurations(),['confml/data.confml'])
|
|
611 |
conf.remove_configuration("confml/data.confml")
|
|
612 |
self.assertEquals(len(conf.list_configurations()),0)
|
|
613 |
|
|
614 |
def test_add_a_include_and_remove_it(self):
|
|
615 |
conf = api.Configuration("simple.confml")
|
|
616 |
conf.include_configuration("confml/data.confml")
|
|
617 |
self.assertEquals(conf.list_configurations(),['confml/data.confml'])
|
|
618 |
conf.remove_configuration("confml/data.confml")
|
|
619 |
self.assertEquals(len(conf.list_configurations()),0)
|
|
620 |
|
|
621 |
def test_add_a_include_with_dots_in_path_and_remove_it(self):
|
|
622 |
conf = api.Configuration("simple.confml")
|
|
623 |
conf.include_configuration("test/foo.bar/data.confml")
|
|
624 |
self.assertEquals(conf.list_configurations(),['test/foo.bar/data.confml'])
|
|
625 |
conf.remove_configuration("test/foo.bar/data.confml")
|
|
626 |
self.assertEquals(len(conf.list_configurations()),0)
|
|
627 |
|
|
628 |
def test_add_a_include_with_dots_and_remove_it(self):
|
|
629 |
conf = api.Configuration("simple.confml")
|
|
630 |
conf.include_configuration("../foo/data.confml")
|
|
631 |
self.assertEquals(conf.list_configurations(),['../foo/data.confml'])
|
|
632 |
conf.remove_configuration("../foo/data.confml")
|
|
633 |
self.assertEquals(len(conf.list_configurations()),0)
|
|
634 |
|
|
635 |
class TestConfigurationData(unittest.TestCase):
|
|
636 |
def test_add_features_and_add_data_via_default_view(self):
|
|
637 |
conf = api.Configuration("foo/foo.confml")
|
|
638 |
conf.add_feature(api.Feature('feature1'))
|
|
639 |
conf.add_feature(api.Feature('feature2'))
|
|
640 |
conf.add_feature(api.Feature('feature3'))
|
|
641 |
conf.add_feature(api.Feature('feature4'))
|
|
642 |
conf.add_feature(api.Feature('feature12'),'feature1')
|
|
643 |
dview = conf.get_default_view()
|
|
644 |
dview.feature1._add_data(api.Data(ref="feature1", value=123))
|
|
645 |
dview.feature2._add_data(api.Data(ref="feature2", value=123))
|
|
646 |
dview.feature3._add_data(api.Data(ref="feature3", value=123))
|
|
647 |
dview.feature1.feature12._add_data(api.Data(ref="feature12", value=123))
|
|
648 |
dview.feature1._add_data(api.Data(ref="feature1", value=123))
|
|
649 |
self.assertEquals(dview.feature1.get_value(), 123)
|
|
650 |
dview.feature1._add_data(api.Data(ref="feature1", value=111))
|
|
651 |
self.assertEquals(dview.feature1.get_value(), 111)
|
|
652 |
|
|
653 |
def test_add_data_to_configuration(self):
|
|
654 |
conf = api.Configuration("foo/foo.confml")
|
|
655 |
conf.add_data(api.Data(ref='feature1', value=123))
|
|
656 |
self.assertEquals(conf.get_data('feature1').get_value(),123)
|
|
657 |
conf.add_data(api.Data(fqr='feature1.feature12', value="test"))
|
|
658 |
self.assertEquals(conf.get_data('feature1.feature12').get_value(),"test")
|
|
659 |
self.assertEquals(conf.data.feature1.feature12.get_value(),"test")
|
|
660 |
conf.remove_data('feature1.feature12')
|
|
661 |
self.assertEquals(conf.list_datas(), ['feature1'])
|
3
|
662 |
|
|
663 |
def test_add_data_to_configuration_from_list(self):
|
|
664 |
def check(data_objs, policy, expected):
|
|
665 |
conf = api.Configuration("foo/foo.confml")
|
|
666 |
conf.add_data(api.Data(ref='base1', value="foo"))
|
|
667 |
conf.add_data(api.Data(ref='foo', value="foobar"))
|
|
668 |
conf.add_data(api.Data(ref='base2', value="bar"))
|
|
669 |
|
|
670 |
if policy is None:
|
|
671 |
conf.add_data(data_objs)
|
|
672 |
else:
|
|
673 |
conf.add_data(data_objs, policy=policy)
|
|
674 |
|
|
675 |
actual = []
|
|
676 |
for d in conf._traverse(type=api.Data):
|
|
677 |
actual.append((d.fqr, d.value))
|
|
678 |
self.assertEquals(actual, expected)
|
|
679 |
|
|
680 |
# Adding an empty list should do nothing
|
|
681 |
check(data_objs = [],
|
|
682 |
policy = None,
|
|
683 |
expected = [('base1', 'foo'),
|
|
684 |
('foo', 'foobar'),
|
|
685 |
('base2', 'bar')])
|
|
686 |
|
|
687 |
# Default policy (replace)
|
|
688 |
check(data_objs = [api.Data(ref="foo", value="1"),
|
|
689 |
api.Data(ref="foo", value="2"),
|
|
690 |
api.Data(ref="foo", value="3"),],
|
|
691 |
policy = None,
|
|
692 |
expected = [('base1', 'foo'),
|
|
693 |
('foo', '1'),
|
|
694 |
('foo', '2'),
|
|
695 |
('foo', '3'),
|
|
696 |
('base2', 'bar')])
|
|
697 |
|
|
698 |
# Replace explicitly
|
|
699 |
check(data_objs = [api.Data(ref="foo", value="1"),
|
|
700 |
api.Data(ref="foo", value="2"),
|
|
701 |
api.Data(ref="foo", value="3"),],
|
|
702 |
policy = api.container.REPLACE,
|
|
703 |
expected = [('base1', 'foo'),
|
|
704 |
('foo', '1'),
|
|
705 |
('foo', '2'),
|
|
706 |
('foo', '3'),
|
|
707 |
('base2', 'bar')])
|
|
708 |
|
|
709 |
# Append
|
|
710 |
check(data_objs = [api.Data(ref="foo", value="1"),
|
|
711 |
api.Data(ref="foo", value="2"),
|
|
712 |
api.Data(ref="foo", value="3"),],
|
|
713 |
policy = api.container.APPEND,
|
|
714 |
expected = [('base1', 'foo'),
|
|
715 |
('foo', 'foobar'),
|
|
716 |
('foo', '1'),
|
|
717 |
('foo', '2'),
|
|
718 |
('foo', '3'),
|
|
719 |
('base2', 'bar')])
|
|
720 |
|
|
721 |
# Prepend
|
|
722 |
check(data_objs = [api.Data(ref="foo", value="1"),
|
|
723 |
api.Data(ref="foo", value="2"),
|
|
724 |
api.Data(ref="foo", value="3"),],
|
|
725 |
policy = api.container.PREPEND,
|
|
726 |
expected = [('base1', 'foo'),
|
|
727 |
('foo', '1'),
|
|
728 |
('foo', '2'),
|
|
729 |
('foo', '3'),
|
|
730 |
('foo', 'foobar'),
|
|
731 |
('base2', 'bar')])
|
0
|
732 |
|
|
733 |
def test_set_data_to_configuration(self):
|
|
734 |
conf = api.Configuration("foo/foo.confml")
|
|
735 |
conf.add_data(api.Data(fqr='feature1', value=123))
|
|
736 |
self.assertEquals(conf.get_data('feature1').get_value(),123)
|
|
737 |
conf.add_data(api.Data(fqr='feature1.feature12', value="test"))
|
|
738 |
self.assertEquals(conf.get_data('feature1.feature12').get_value(),"test")
|
|
739 |
self.assertEquals(conf.data.feature1.feature12.get_value(),"test")
|
|
740 |
|
|
741 |
def test_add_features_and_add_data_via_features(self):
|
|
742 |
conf = api.Configuration("foo/foo.confml")
|
|
743 |
conf.add_feature(api.Feature('feature1'))
|
|
744 |
conf.add_feature(api.Feature('feature2'))
|
|
745 |
conf.add_feature(api.Feature('feature3'))
|
|
746 |
conf.add_feature(api.Feature('feature4'))
|
|
747 |
conf.add_feature(api.Feature('feature12'),'feature1')
|
|
748 |
conf.feature1.set_value(123)
|
|
749 |
conf.feature1.feature12.set_value("test")
|
|
750 |
self.assertEquals(conf.feature1.get_value(),123)
|
|
751 |
self.assertEquals(conf.feature1.feature12.get_value(),"test")
|
|
752 |
|
|
753 |
def test_create_layers_add_features_and_add_data_via_features(self):
|
|
754 |
conf = api.Configuration("foo/foo.confml")
|
|
755 |
conf.add_feature(api.Feature('feature1'))
|
|
756 |
conf.add_feature(api.Feature('feature2'))
|
|
757 |
conf.add_feature(api.Feature('feature3'))
|
|
758 |
conf.add_feature(api.Feature('feature4'))
|
|
759 |
conf.add_feature(api.Feature('feature12'),'feature1')
|
|
760 |
conf.feature1.set_value(123)
|
|
761 |
self.assertEquals(conf.feature1.get_value(),123)
|
|
762 |
conf.create_configuration("layer1.confml")
|
|
763 |
conf.feature1.feature12.set_value("test")
|
|
764 |
self.assertEquals(conf.feature1.get_data().find_parent(type=api.Configuration),conf)
|
|
765 |
self.assertEquals(conf.feature1.feature12.get_value(),"test")
|
|
766 |
|
|
767 |
conf.feature1.set_value(321)
|
|
768 |
conf.create_configuration("layer2.confml")
|
|
769 |
self.assertEquals(conf.layer2_confml.list_datas(), [])
|
|
770 |
|
|
771 |
self.assertEquals(conf.feature1.get_value(),321)
|
|
772 |
self.assertEquals(conf.feature1.get_data().find_parent(type=api.Configuration).get_path(),conf.get_configuration("layer1.confml").get_path())
|
|
773 |
self.assertEquals(conf.layer1_confml.list_all_datas(), ['feature1','feature1.feature12'])
|
|
774 |
self.assertEquals([data.get_value() for data in conf.layer1_confml.get_all_datas()], [321,'test'])
|
|
775 |
self.assertEquals(conf.list_datas(), ['feature1'])
|
|
776 |
self.assertEquals([data.find_parent(type=api.Configuration).get_path() for data in conf.get_all_datas()],
|
|
777 |
['foo/foo.confml',
|
|
778 |
'layer1.confml',
|
|
779 |
'layer1.confml',])
|
|
780 |
|
|
781 |
def test_create_layers_add_featuresequence_and_add_data_via_features(self):
|
|
782 |
conf = api.Configuration("foo/foo.confml")
|
|
783 |
conf.add_feature(api.FeatureSequence('feature1'))
|
|
784 |
conf.add_feature(api.Feature('child1'),'feature1')
|
|
785 |
conf.add_feature(api.Feature('child2'),'feature1')
|
|
786 |
conf.add_feature(api.Feature('child3'),'feature1')
|
|
787 |
conf.feature1.add_sequence()
|
|
788 |
conf.feature1.get_data()[0][0].set_value('test1')
|
|
789 |
conf.feature1.get_data()[0][1].set_value('test2')
|
|
790 |
conf.feature1.get_data()[0][2].set_value('test3')
|
|
791 |
conf.feature1.add_sequence(['foo1','foo2','foo3'])
|
|
792 |
self.assertEquals(conf.feature1.get_data()[1][0].get_value(),'foo1')
|
|
793 |
self.assertEquals(conf.feature1.get_data()[1][1].get_value(),'foo2')
|
|
794 |
self.assertEquals(conf.feature1.get_data()[1][2].get_value(),'foo3')
|
|
795 |
self.assertEquals(conf.feature1.get_value(),
|
|
796 |
[['test1','test2','test3'],
|
|
797 |
['foo1','foo2','foo3']])
|
|
798 |
self.assertEquals(conf.list_all_datas(),['feature1', 'feature1.child1', 'feature1.child2', 'feature1.child3', 'feature1', 'feature1.child1', 'feature1.child2', 'feature1.child3'])
|
|
799 |
|
|
800 |
def test_create_featuresequence_and_get_empty_data(self):
|
|
801 |
conf = api.Configuration("foo/foo.confml")
|
|
802 |
conf.add_feature(api.FeatureSequence('feature1'))
|
|
803 |
conf.add_feature(api.Feature('child1'),'feature1')
|
|
804 |
conf.add_feature(api.Feature('child2'),'feature1')
|
|
805 |
conf.add_feature(api.Feature('child3'),'feature1')
|
|
806 |
self.assertEquals(conf.get_feature('feature1').get_data(),[])
|
|
807 |
self.assertEquals(conf.get_feature('feature1').get_value(),[])
|
|
808 |
|
|
809 |
def test_create_featuresequence_and_set_template(self):
|
|
810 |
conf = api.Configuration("foo/foo.confml")
|
|
811 |
conf.add_feature(api.FeatureSequence('feature1'))
|
|
812 |
conf.add_feature(api.Feature('child1'),'feature1')
|
|
813 |
conf.add_feature(api.Feature('child2'),'feature1')
|
|
814 |
conf.add_feature(api.Feature('child3'),'feature1')
|
|
815 |
fea = conf.get_feature('feature1')
|
|
816 |
fea.set_template(['test1','test2','test3'])
|
|
817 |
self.assertEquals(fea.get_template(),['test1', 'test2', 'test3'])
|
3
|
818 |
fea.set_template(['Test1','Test2','Test3'])
|
|
819 |
self.assertEquals(fea.get_template(),['Test1','Test2','Test3'])
|
|
820 |
|
|
821 |
self.assertRaises(ValueError, fea.set_template, [])
|
|
822 |
self.assertRaises(ValueError, fea.set_template, ['foo', 'bar'])
|
|
823 |
self.assertRaises(ValueError, fea.set_template, ['foo', 'bar', 'foo', 'bar'])
|
0
|
824 |
|
|
825 |
def test_create_features_with_rfs_data(self):
|
|
826 |
conf = api.Configuration("foo/foo.confml")
|
|
827 |
conf.add_feature(api.Feature('feature1'))
|
|
828 |
conf.add_feature(api.Feature('child1'),'feature1')
|
|
829 |
conf.add_feature(api.Feature('child2'),'feature1')
|
|
830 |
conf.add_feature(api.Feature('child3'),'feature1')
|
|
831 |
|
|
832 |
conf.add_data(api.Data(fqr='feature1.child1',attr='rfs',value='true'))
|
|
833 |
conf.add_data(api.Data(fqr='feature1.child2',attr='rfs',value='false'))
|
|
834 |
dview = conf.get_default_view()
|
|
835 |
self.assertEquals(dview.get_feature('feature1.child1').get_value(), None)
|
|
836 |
self.assertEquals(dview.get_feature('feature1.child1').get_value('rfs'), 'true')
|
|
837 |
self.assertEquals(dview.get_feature('feature1.child2').get_value('rfs'), 'false')
|
|
838 |
|
|
839 |
class TestConfigurationDictStoring(unittest.TestCase):
|
|
840 |
|
|
841 |
def test_dumps_simple(self):
|
|
842 |
root = api.Configuration("root",namespace="com.nokia")
|
|
843 |
conf = root.create_configuration("test.confml")
|
|
844 |
dumped = persistentdictionary.DictWriter().dumps(conf)
|
|
845 |
dict =dumped['Configuration']['dict']
|
|
846 |
self.assertEquals(dict['path'],'test.confml')
|
|
847 |
self.assertEquals(dict['namespace'],'com.nokia')
|
|
848 |
|
|
849 |
def test_dumps_add_features(self):
|
|
850 |
root = api.Configuration("root",namespace="com.nokia")
|
|
851 |
conf = root.create_configuration("test.confml")
|
3
|
852 |
conf.add_feature(api.Feature("feature1", name="feature1"))
|
|
853 |
conf.add_feature(api.Feature("feature2", name="feature2"))
|
0
|
854 |
dumped = persistentdictionary.DictWriter().dumps(conf)
|
|
855 |
dict =dumped['Configuration']['dict']
|
|
856 |
self.assertEquals(dict['path'],'test.confml')
|
|
857 |
self.assertEquals(dict['namespace'],'com.nokia')
|
|
858 |
self.assertEquals(dumped['Configuration']['children'],
|
|
859 |
[{'Feature': {'dict': {'name': 'feature1', 'ref': 'feature1'}}},
|
|
860 |
{'Feature': {'dict': {'name': 'feature2', 'ref': 'feature2'}}}]
|
|
861 |
)
|
|
862 |
|
|
863 |
def test_dumps_root_configuration(self):
|
|
864 |
root = api.Configuration("root",namespace="com.nokia")
|
|
865 |
conf = root.create_configuration("foo/root.confml")
|
|
866 |
conf.add_feature(api.Feature("feature1"))
|
|
867 |
conf.add_feature(api.Feature("feature2"))
|
|
868 |
conf.feature1.add_feature(api.Feature("feature11"))
|
|
869 |
conf.feature1.add_feature(api.Feature("feature12"))
|
|
870 |
dumped = persistentdictionary.DictWriter().dumps(root)
|
|
871 |
dict =dumped['Configuration']['dict']
|
|
872 |
self.assertEquals(dict['ref'],'root')
|
|
873 |
self.assertEquals(dict['namespace'],'com.nokia')
|
|
874 |
|
|
875 |
def test_dumps_feature_hierarchy(self):
|
|
876 |
root = api.Configuration("root",namespace="com.nokia")
|
|
877 |
conf = root.create_configuration("test.confml")
|
3
|
878 |
conf.add_feature(api.Feature("feature1", name="feature1"))
|
|
879 |
conf.add_feature(api.Feature("feature2", name="feature2"))
|
|
880 |
conf.feature1.add_feature(api.Feature("feature11", name="feature11"))
|
|
881 |
conf.feature1.add_feature(api.Feature("feature12", name="feature12"))
|
0
|
882 |
dumped = persistentdictionary.DictWriter().dumps(conf)
|
|
883 |
dict =dumped['Configuration']['dict']
|
|
884 |
self.assertEquals(dict['path'],'test.confml')
|
|
885 |
self.assertEquals(dict['ref'],'test_confml')
|
|
886 |
self.assertEquals(dict['namespace'],'com.nokia')
|
|
887 |
self.assertEquals(dumped['Configuration']['children'],
|
|
888 |
[{'Feature': {'dict': {'name': 'feature1', 'ref': 'feature1'},
|
|
889 |
'children': [
|
|
890 |
{'Feature': {'dict': {'name': 'feature11', 'ref': 'feature11'}}},
|
|
891 |
{'Feature': {'dict': {'name': 'feature12', 'ref': 'feature12'}}}]}},
|
|
892 |
{'Feature': {'dict': {'name': 'feature2', 'ref': 'feature2'}}}
|
|
893 |
])
|
|
894 |
|
|
895 |
def test_loads(self):
|
|
896 |
conf = persistentdictionary.DictReader().loads({'Configuration': {'dict' : {'namespace':'test','ref':'test.confml'}}} )
|
|
897 |
self.assertTrue(isinstance(conf,api.Configuration))
|
|
898 |
self.assertEquals(conf.namespace,'test')
|
|
899 |
self.assertEquals(conf.get_ref(),'test.confml')
|
|
900 |
|
|
901 |
def test_loads_with_features(self):
|
|
902 |
root = api.Configuration("root",namespace="com.nokia")
|
|
903 |
conf = persistentdictionary.DictReader().loads({
|
|
904 |
'Configuration': {'dict' : {'namespace':'test','ref':'test.confml'},
|
|
905 |
'children': [{'Feature': {'dict': {'ref': 'feature1'},
|
|
906 |
'children': [
|
|
907 |
{'Feature': {'dict': {'ref': 'feature11'}}},
|
|
908 |
{'Feature': {'dict': {'ref': 'feature12'}}}]
|
|
909 |
}
|
|
910 |
},
|
|
911 |
{'Feature': {'dict': {'ref': 'feature2'}}}]}} )
|
|
912 |
|
|
913 |
self.assertEquals(conf.namespace,'test')
|
|
914 |
self.assertEquals(conf.ref,'test.confml')
|
|
915 |
root.add_configuration(conf)
|
|
916 |
self.assertEquals(root.list_all_features(),['test.feature1',
|
|
917 |
'test.feature1.feature11',
|
|
918 |
'test.feature1.feature12',
|
|
919 |
'test.feature2'])
|
|
920 |
|
|
921 |
|
|
922 |
def test_dumps_and_loads(self):
|
|
923 |
conf = api.Configuration("test.confml")
|
|
924 |
conf.add_feature(api.Feature("feature1"))
|
|
925 |
conf.add_feature(api.Feature("feature2"))
|
|
926 |
conf.feature1.add_feature(api.Feature("feature11"))
|
|
927 |
conf.feature1.add_feature(api.Feature("feature12"))
|
|
928 |
dumped = persistentdictionary.DictWriter().dumps(conf)
|
|
929 |
|
|
930 |
conf2 = persistentdictionary.DictReader().loads(dumped)
|
|
931 |
self.assertEquals(conf.list_all_features(),
|
|
932 |
conf2.list_all_features())
|
|
933 |
|
|
934 |
def test_dumps_and_loads_configuration_hierarchy(self):
|
|
935 |
root = api.Configuration("root.confml")
|
3
|
936 |
root.add_configuration(api.Configuration("layer1"))
|
|
937 |
layer = api.Configuration("layer2")
|
|
938 |
conf = api.Configuration("test")
|
0
|
939 |
conf.add_feature(api.Feature("feature1"))
|
|
940 |
conf.add_feature(api.Feature("feature2"))
|
|
941 |
conf.feature1.add_feature(api.Feature("feature11"))
|
|
942 |
conf.feature1.add_feature(api.Feature("feature12"))
|
|
943 |
layer.add_configuration(conf)
|
|
944 |
root.add_configuration(layer)
|
|
945 |
dumped = persistentdictionary.DictWriter().dumps(root)
|
|
946 |
|
|
947 |
root2= persistentdictionary.DictReader().loads(dumped)
|
|
948 |
self.assertEquals(root.list_all_features(),
|
|
949 |
root2.list_all_features())
|
|
950 |
|
|
951 |
def test_dumps_and_loads_configuration_hierarchy_with_data(self):
|
|
952 |
root = api.Configuration("root.confml")
|
3
|
953 |
layer = api.Configuration("layer1")
|
|
954 |
conf = api.Configuration("test")
|
0
|
955 |
conf.add_feature(api.Feature("feature1"))
|
|
956 |
conf.add_feature(api.Feature("feature2"))
|
|
957 |
conf.feature1.add_feature(api.Feature("feature11"))
|
|
958 |
conf.feature1.add_feature(api.Feature("feature12"))
|
|
959 |
conf.feature1.set_value(1)
|
|
960 |
conf.feature2.set_value(2)
|
|
961 |
layer.add_configuration(conf)
|
|
962 |
root.add_configuration(layer)
|
3
|
963 |
root.add_configuration(api.Configuration("layer2"))
|
0
|
964 |
root.get_default_view().feature1.feature11.set_value("testing11")
|
|
965 |
root.get_default_view().feature1.set_value("test1")
|
|
966 |
dumped = persistentdictionary.DictWriter().dumps(root)
|
|
967 |
root2= persistentdictionary.DictReader().loads(dumped)
|
|
968 |
self.assertEquals(root.list_all_features(),
|
|
969 |
root2.list_all_features())
|
|
970 |
self.assertEquals(root2.get_default_view().feature1.get_value(), "test1")
|
|
971 |
self.assertEquals(root2.get_default_view().feature2.get_value(), 2)
|
|
972 |
self.assertEquals(root2.get_default_view().feature1.feature11.get_value(), "testing11")
|
|
973 |
|
|
974 |
self.assertEquals([data.find_parent(type=api.Configuration).get_path() for data in root2.get_all_datas()],
|
3
|
975 |
['test', 'test', 'layer2','layer2'])
|
0
|
976 |
|
|
977 |
def test_access_via_configuration_proxy(self):
|
|
978 |
conf = api.Configuration("root.confml")
|
|
979 |
conf.add_feature(api.Feature("feature1"))
|
|
980 |
proxy = api.ConfigurationProxy("root.confml")
|
3
|
981 |
proxy._set_obj(conf)
|
0
|
982 |
self.assertEquals(proxy.get_ref(), 'root_confml')
|
|
983 |
self.assertEquals(proxy.get_path(), 'root.confml')
|
|
984 |
self.assertEquals(conf.feature1.get_ref(), 'feature1')
|
|
985 |
self.assertEquals(proxy.feature1.get_ref(), 'feature1')
|
|
986 |
|
|
987 |
|
3
|
988 |
class TestConfigurationInclude(unittest.TestCase):
|
|
989 |
class StoreTestInt(object):
|
|
990 |
def load(self, ref):
|
|
991 |
return api.Configuration(ref)
|
|
992 |
|
|
993 |
def dump(self, obj, ref):
|
|
994 |
pass
|
|
995 |
|
|
996 |
def get_store_interface(self):
|
|
997 |
return TestConfigurationInclude.StoreTestInt()
|
|
998 |
|
|
999 |
def _test_include(self):
|
|
1000 |
inc = api.Include("foo/bar.txt", self.get_store_interface())
|
|
1001 |
objs =inc._objects()
|
|
1002 |
self.assertEquals(len(objs),1)
|
|
1003 |
self.assertEquals(objs[0].path,"foo/bar.txt")
|
|
1004 |
|
|
1005 |
def test_include_clone(self):
|
|
1006 |
inc = api.Include("foo/bar.txt", store_interface=self.get_store_interface())
|
|
1007 |
ci = inc._clone()
|
|
1008 |
self.assertEquals(inc.ref, ci.ref)
|
|
1009 |
self.assertEquals(inc.get_path(), ci.get_path())
|
|
1010 |
|
|
1011 |
# def test_configuration_with_include(self):
|
|
1012 |
# conf = api.Configuration("foo.confml")
|
|
1013 |
# # Set the get_store_interface function to test stub method
|
|
1014 |
# conf.get_store_interface = self.get_store_interface
|
|
1015 |
# conf.include_configuration("foo/test.confml")
|
|
1016 |
# subconfs = conf.list_configurations()
|
|
1017 |
# self.assertEquals(len(subconfs),1)
|
|
1018 |
# self.assertTrue(isinstance(subconfs[0], api.Configuration))
|
|
1019 |
# self.assertEquals(subconfs[0].path,"foo/test.confml")
|
|
1020 |
|
0
|
1021 |
if __name__ == '__main__':
|
3
|
1022 |
unittest.main()
|
0
|
1023 |
|
|
1024 |
"""
|
|
1025 |
{'Configuration': {'dict': {'path': 'root.confml', 'ref': 'root', 'namespace': '', 'desc': ''}, 'children': [{'Configuration': {'dict': {'path': 'foo/layer1.confml', 'ref': 'foo_layer1', 'namespace': '', 'desc': ''}, 'children': [{'Configuration': {'dict': {'path': 'foo/test.confml', 'ref': 'foo_test', 'namespace': '', 'desc': ''}, 'children': [{'Feature': {'dict': {'ref': 'feature1'}, 'children': [{'Feature': {'dict': {'ref': 'feature11'}}}, {'Feature': {'dict': {'ref': 'feature12'}}}]}}, {'Feature': {'dict': {'ref': 'feature2'}}}, {'DataContainer': {'dict': {'ref': 'data'}, 'children': [{'Data': {'dict': {'ref': 'feature1', 'value': 1}}}, {'Data': {'dict': {'ref': 'feature2', 'value': 2}}}]}}]}}]}}, {'Configuration': {'dict': {'path': 'layer2.confml', 'ref': 'layer2', 'namespace': '', 'desc': ''}}}]}}
|
|
1026 |
"""
|