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:
|
|
15 |
#
|
|
16 |
|
|
17 |
import unittest
|
|
18 |
import os
|
3
|
19 |
|
0
|
20 |
from cone.public import *
|
|
21 |
from cone.public import _plugin_reader
|
4
|
22 |
from testautomation.utils import remove_if_exists
|
|
23 |
import pickle
|
0
|
24 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
25 |
|
|
26 |
Tfd = _plugin_reader.TempVariableDefinition
|
|
27 |
Tsfd = _plugin_reader.TempVariableSequenceDefinition
|
|
28 |
Sro = _plugin_reader.SettingRefsOverride
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
MULTI_IMPL_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
33 |
<common:container xmlns:common="http://www.symbianfoundation.org/xml/implml/1">
|
|
34 |
<impl xmlns="http://www.test.com/xml/1">
|
|
35 |
<elem x="1" y="2"/>
|
|
36 |
</impl>
|
|
37 |
|
|
38 |
<impl xmlns="http://www.test.com/xml/2">
|
|
39 |
<dummy z="500"/>
|
|
40 |
<elem x="10" y="20"/>
|
|
41 |
</impl>
|
|
42 |
|
|
43 |
<impl xmlns="http://www.test.com/xml/3">
|
|
44 |
<elem x="100" y="200"/>
|
|
45 |
<elem z="300"/>
|
|
46 |
</impl>
|
|
47 |
</common:container>
|
|
48 |
""".encode('utf-8')
|
|
49 |
|
|
50 |
MULTI_IMPL_2 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
51 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1"
|
|
52 |
xmlns:ns0="http://www.test.com/xml/1"
|
|
53 |
xmlns:ns2="http://www.test.com/xml/2"
|
|
54 |
xmlns:ns3="http://www.test.com/xml/3">
|
|
55 |
|
|
56 |
<ns0:impl>
|
|
57 |
<ns0:elem x="1" y="2"/>
|
|
58 |
</ns0:impl>
|
|
59 |
|
|
60 |
<ns2:impl>
|
|
61 |
<ns2:dummy z="500"/>
|
|
62 |
<ns2:elem x="10" y="20"/>
|
|
63 |
</ns2:impl>
|
|
64 |
|
|
65 |
<ns3:impl>
|
|
66 |
<ns3:elem x="100" y="200"/>
|
|
67 |
<ns3:elem z="300"/>
|
|
68 |
</ns3:impl>
|
|
69 |
</container>
|
|
70 |
""".encode('utf-8')
|
|
71 |
|
|
72 |
MULTI_IMPL_3 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
73 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
74 |
<impl1:impl xmlns:impl1="http://www.test.com/xml/1">
|
|
75 |
<impl1:elem x="1" y="2"/>
|
|
76 |
</impl1:impl>
|
|
77 |
|
|
78 |
<impl2:impl xmlns:impl2="http://www.test.com/xml/2">
|
|
79 |
<impl2:elem x="1" y="2"/>
|
|
80 |
</impl2:impl>
|
|
81 |
|
|
82 |
<impl1:impl xmlns:impl1="http://www.test.com/xml/1">
|
|
83 |
<impl1:elem a="1" b="2"/>
|
|
84 |
</impl1:impl>
|
|
85 |
|
|
86 |
<impl2:impl xmlns:impl2="http://www.test.com/xml/2">
|
|
87 |
<impl2:elem a="1" b="2"/>
|
|
88 |
</impl2:impl>
|
|
89 |
</container>
|
|
90 |
""".encode('utf-8')
|
|
91 |
|
|
92 |
UNSUPPORTED_IMPL_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
93 |
<test_impl>
|
|
94 |
<impl xmlns="http://www.test.com/xml/1">
|
|
95 |
<elem x="1" y="2"/>
|
|
96 |
</impl>
|
|
97 |
|
|
98 |
<impl xmlns="http://www.test.com/xml/2">
|
|
99 |
<dummy z="500"/>
|
|
100 |
<elem x="10" y="20"/>
|
|
101 |
</impl>
|
|
102 |
|
|
103 |
<impl xmlns="http://www.test.com/xml/4">
|
|
104 |
<elem x="1" y="2"/>
|
|
105 |
</impl>
|
|
106 |
</test_impl>
|
|
107 |
""".encode('utf-8')
|
|
108 |
|
|
109 |
UNSUPPORTED_IMPL_2 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
110 |
<test_impl xmlns="http://www.test.com/xml/6"
|
|
111 |
xmlns:ns2="http://www.test.com/xml/2"
|
|
112 |
xmlns:ns4="http://www.test.com/xml/4">
|
|
113 |
|
|
114 |
<elem x="1" y="2"/>
|
|
115 |
|
|
116 |
<ns2:dummy z="500"/>
|
|
117 |
<ns2:elem x="10" y="20"/>
|
|
118 |
|
|
119 |
<ns4:elem x="1" y="2"/>
|
|
120 |
</test_impl>
|
|
121 |
""".encode('utf-8')
|
|
122 |
|
|
123 |
SINGLE_IMPL_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
124 |
<impl xmlns="http://www.test.com/xml/1">
|
|
125 |
<elem x="1"/>
|
|
126 |
<elem y="2"/>
|
|
127 |
<elem z="3"/>
|
|
128 |
</impl>
|
|
129 |
""".encode('utf-8')
|
|
130 |
|
|
131 |
SINGLE_IMPL_2 = """<?xml version="1.0" encoding="UTF-8"?>
|
3
|
132 |
<impl xmlns="http://www.test.com/xml/2"/>
|
0
|
133 |
""".encode('utf-8')
|
|
134 |
|
|
135 |
SINGLE_IMPL_3 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
136 |
<impl xmlns="http://www.test.com/xml/3">
|
|
137 |
<elem x="1"/>
|
|
138 |
</impl>
|
|
139 |
""".encode('utf-8')
|
|
140 |
|
|
141 |
NO_IMPL = """<?xml version="1.0" encoding="UTF-8"?>
|
|
142 |
<impl>
|
|
143 |
</impl>
|
|
144 |
""".encode('utf-8')
|
|
145 |
|
|
146 |
class Mock(object):
|
|
147 |
pass
|
|
148 |
|
|
149 |
class MockView(object):
|
|
150 |
def __init__(self, feature_dict):
|
|
151 |
self.feature_dict = feature_dict
|
|
152 |
|
|
153 |
def get_feature(self, ref):
|
|
154 |
feature = Mock()
|
|
155 |
feature.get_value = lambda: self.feature_dict[ref]
|
|
156 |
feature.get_original_value = lambda: self.feature_dict[ref]
|
|
157 |
return feature
|
|
158 |
|
|
159 |
class MockConfiguration(object):
|
|
160 |
def __init__(self, resources, features={}):
|
|
161 |
self.resources = resources
|
|
162 |
self.features = features
|
|
163 |
|
|
164 |
def get_resource(self, ref):
|
|
165 |
res = Mock()
|
|
166 |
res.read = lambda: self.resources[ref]
|
|
167 |
res.close = lambda: None
|
|
168 |
return res
|
|
169 |
|
|
170 |
def get_layer(self):
|
|
171 |
layer = Mock()
|
|
172 |
layer.list_implml = lambda: self.resources.keys()
|
|
173 |
return layer
|
|
174 |
|
|
175 |
def get_doc(self, ref):
|
|
176 |
return utils.etree.fromstring(self.get_resource(ref).read())
|
|
177 |
|
|
178 |
def get_default_view(self):
|
|
179 |
return MockView(self.features)
|
3
|
180 |
|
|
181 |
def layered_implml(self):
|
|
182 |
result = container.DataContainer()
|
|
183 |
for res in self.resources.iterkeys():
|
|
184 |
result.add_value(res, res)
|
|
185 |
return result
|
|
186 |
|
|
187 |
class SimpleImpl(plugin.ImplBase):
|
|
188 |
def __init__(self, ref, configuration):
|
|
189 |
super(SimpleImpl, self).__init__(ref, configuration)
|
|
190 |
self.generate_invoked = False
|
|
191 |
self.outputfile = ''
|
|
192 |
|
|
193 |
def generate(self, context=None):
|
|
194 |
if context:
|
|
195 |
if self.outputfile:
|
|
196 |
f = context.create_file(self.outputfile, implementation=self)
|
|
197 |
f.close()
|
|
198 |
|
|
199 |
self.generate_invoked = True
|
0
|
200 |
|
|
201 |
class MockImpl(plugin.ImplBase):
|
3
|
202 |
IMPL_TYPE_ID = 'mock'
|
|
203 |
|
0
|
204 |
def __init__(self, data):
|
|
205 |
self.data = data
|
|
206 |
self.generate_invoked = False
|
3
|
207 |
self.outputfile = ''
|
|
208 |
self.refs = None
|
|
209 |
self.ref = ''
|
|
210 |
|
0
|
211 |
@classmethod
|
|
212 |
def create(cls, resource_ref, configuration, data):
|
|
213 |
impl = cls(data)
|
|
214 |
plugin.ImplBase.__init__(impl, resource_ref, configuration)
|
|
215 |
return impl
|
|
216 |
|
|
217 |
def generate(self, context=None):
|
|
218 |
if context and hasattr(context,'objects'):
|
|
219 |
context.objects.append(self)
|
|
220 |
self.generate_invoked = True
|
|
221 |
|
|
222 |
def __repr__(self):
|
|
223 |
return "MockImpl(%r)" % self.data
|
|
224 |
|
|
225 |
def __eq__(self, other):
|
|
226 |
if type(self) == type(other):
|
|
227 |
return self.data == other.data
|
|
228 |
else:
|
|
229 |
return False
|
|
230 |
|
|
231 |
def __ne__(self, other):
|
|
232 |
return not (self == other)
|
|
233 |
|
|
234 |
def __lt__(self, other):
|
|
235 |
if type(self) == type(other):
|
|
236 |
return self.data < other.data
|
|
237 |
else:
|
|
238 |
return False
|
|
239 |
|
3
|
240 |
def get_refs(self):
|
|
241 |
"""
|
|
242 |
Return a list of all ConfML setting references that affect this
|
|
243 |
implementation. May also return None if references are not relevant
|
|
244 |
for the implementation.
|
|
245 |
"""
|
|
246 |
return self.refs
|
|
247 |
|
0
|
248 |
class MockReaderBase(plugin.ReaderBase):
|
|
249 |
@classmethod
|
|
250 |
def read_impl(cls, resource_ref, configuration, root_elem):
|
|
251 |
data = [cls.__name__, resource_ref]
|
|
252 |
for elem in root_elem.findall('{%s}elem' % cls.NAMESPACE):
|
|
253 |
data.append(elem.attrib)
|
|
254 |
return MockImpl.create(resource_ref, configuration, data)
|
|
255 |
|
|
256 |
class MockReader1(MockReaderBase):
|
|
257 |
NAMESPACE = "http://www.test.com/xml/1"
|
3
|
258 |
NAMESPACE_ID = "mock1"
|
|
259 |
ROOT_ELEMENT_NAME = "impl"
|
0
|
260 |
FILE_EXTENSIONS = ['mock1ml']
|
|
261 |
class MockReader2(MockReaderBase):
|
|
262 |
NAMESPACE = "http://www.test.com/xml/2"
|
3
|
263 |
NAMESPACE_ID = "mock2"
|
|
264 |
ROOT_ELEMENT_NAME = "impl"
|
0
|
265 |
FILE_EXTENSIONS = ['mock2ml']
|
|
266 |
class MockReader3(MockReaderBase):
|
|
267 |
NAMESPACE = "http://www.test.com/xml/3"
|
3
|
268 |
NAMESPACE_ID = "mock3"
|
|
269 |
ROOT_ELEMENT_NAME = "impl"
|
0
|
270 |
IGNORED_NAMESPACES = ["http://www.test.com/xml/ignored/3"]
|
|
271 |
FILE_EXTENSIONS = ['mock3ml', 'test3ml']
|
|
272 |
|
|
273 |
MOCK_READER_CLASSES = [MockReader1, MockReader2, MockReader3]
|
|
274 |
|
|
275 |
mock_config = MockConfiguration({
|
|
276 |
'layer1/implml/multi1.implml' : MULTI_IMPL_1,
|
|
277 |
'layer1/implml/multi2.implml' : MULTI_IMPL_2,
|
|
278 |
'layer1/implml/multi3.implml' : MULTI_IMPL_3,
|
|
279 |
'layer1/implml/unsupported1.implml' : UNSUPPORTED_IMPL_1,
|
|
280 |
'layer1/implml/unsupported2.implml' : UNSUPPORTED_IMPL_2,
|
|
281 |
'layer1/implml/single1.implml' : SINGLE_IMPL_1,
|
|
282 |
'layer1/implml/single2.implml' : SINGLE_IMPL_2,
|
|
283 |
'layer1/implml/single3.implml' : SINGLE_IMPL_3,
|
|
284 |
'layer1/implml/none.implml' : NO_IMPL,
|
|
285 |
'layer1/implml/broken.implml' : 'Some invalid XML data...',
|
|
286 |
'layer1/implml/single1.mock1ml' : SINGLE_IMPL_1,
|
|
287 |
'layer1/implml/single2.mock2ml' : SINGLE_IMPL_2,
|
|
288 |
'layer1/implml/single3.mock3ml' : SINGLE_IMPL_3,
|
|
289 |
'layer1/implml/single3.test3ml' : SINGLE_IMPL_3,
|
|
290 |
'layer1/implml/multi1.dummyml' : MULTI_IMPL_1,
|
|
291 |
'layer1/implml/dummy' : MULTI_IMPL_1,
|
|
292 |
})
|
|
293 |
|
3
|
294 |
|
|
295 |
class TestPluginGenerationContext(unittest.TestCase):
|
|
296 |
def test_generation_context_handle_terminal(self):
|
|
297 |
config = api.Configuration()
|
|
298 |
context = plugin.GenerationContext(configuration=config)
|
|
299 |
self.assertRaises(exceptions.NotFound, context.handle_terminal, 'feature')
|
|
300 |
config.create_feature('feature')
|
|
301 |
# rebuild default view
|
|
302 |
config._remove('?default_view')
|
|
303 |
self.assertEquals(context.handle_terminal('feature'), None)
|
|
304 |
|
|
305 |
|
|
306 |
def test_generation_create_file(self):
|
|
307 |
config = api.Configuration()
|
|
308 |
context = plugin.GenerationContext(configuration=config,
|
|
309 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
310 |
phase="normal")
|
|
311 |
mi = MockImpl({})
|
|
312 |
outfile = context.create_file('foobar/test.txt', implementation=mi)
|
|
313 |
outfile.write("Test output file creation")
|
|
314 |
outfile.close()
|
|
315 |
expected = utils.resourceref.norm(os.path.join(context.output, 'foobar/test.txt'))
|
|
316 |
self.assertEquals(len(context.generation_output), 1)
|
|
317 |
self.assertEquals(context.generation_output[0].name, expected)
|
|
318 |
self.assertEquals(context.generation_output[0].implementation, mi)
|
|
319 |
self.assertEquals(context.generation_output[0].phase, "normal")
|
|
320 |
self.assertTrue(os.path.exists(expected))
|
|
321 |
os.unlink(expected)
|
|
322 |
|
|
323 |
absfile = utils.resourceref.norm(os.path.join(ROOT_PATH, 'temp/foobar/abspath.txt'))
|
|
324 |
outfile = context.create_file(absfile, implementation=mi)
|
|
325 |
outfile.write("Test output file creation")
|
|
326 |
outfile.close()
|
|
327 |
self.assertEquals(len(context.generation_output), 2)
|
|
328 |
self.assertEquals(context.generation_output[1].name, absfile)
|
|
329 |
self.assertEquals(context.generation_output[1].implementation, mi)
|
|
330 |
self.assertEquals(context.generation_output[1].phase, "normal")
|
|
331 |
self.assertTrue(os.path.exists(absfile))
|
|
332 |
os.unlink(absfile)
|
|
333 |
|
|
334 |
def test_generation_add_output(self):
|
|
335 |
config = api.Configuration()
|
|
336 |
context = plugin.GenerationContext(configuration=config,
|
|
337 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
338 |
phase="normal")
|
|
339 |
mi = MockImpl({})
|
|
340 |
context.add_file('add.txt', implementation=mi)
|
|
341 |
|
|
342 |
self.assertEquals(len(context.generation_output), 1)
|
|
343 |
self.assertEquals(context.generation_output[0].name, utils.resourceref.norm(os.path.join(context.output, 'add.txt')))
|
|
344 |
self.assertEquals(context.generation_output[0].implementation, mi)
|
|
345 |
self.assertEquals(context.generation_output[0].phase, "normal")
|
|
346 |
|
|
347 |
external_output = utils.resourceref.norm(os.path.join(ROOT_PATH, 'temp', 'external/foobar.txt'))
|
|
348 |
context.add_file(external_output, implementation=mi)
|
|
349 |
self.assertEquals(len(context.generation_output), 2)
|
|
350 |
self.assertEquals(context.generation_output[1].name, external_output)
|
|
351 |
self.assertEquals(context.generation_output[1].implementation, mi)
|
|
352 |
self.assertEquals(context.generation_output[1].phase, "normal")
|
|
353 |
|
|
354 |
def test_generation_get_output(self):
|
|
355 |
config = api.Configuration()
|
|
356 |
context = plugin.GenerationContext(configuration=config,
|
|
357 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
358 |
phase="normal")
|
|
359 |
mi = MockImpl({})
|
|
360 |
context.add_file('add1.txt', implementation=mi)
|
|
361 |
context.add_file('foo/add2.txt', implementation=None)
|
|
362 |
|
|
363 |
self.assertEquals(len(context.get_output()), 2)
|
|
364 |
self.assertEquals(context.get_output()[1].filename, 'add2.txt')
|
|
365 |
self.assertEquals(context.get_output()[1].abspath, os.path.normpath(os.path.join(context.output,'foo/add2.txt')))
|
|
366 |
self.assertEquals(context.get_output()[1].relpath, os.path.normpath('foo/add2.txt'))
|
|
367 |
self.assertEquals(len(context.get_output(implml_type='mock')), 1)
|
|
368 |
self.assertEquals(context.get_output(implml_type='mock')[0].filename, 'add1.txt')
|
|
369 |
|
|
370 |
def test_generation_get_refs_no_output(self):
|
|
371 |
config = api.Configuration()
|
|
372 |
context = plugin.GenerationContext(configuration=config,
|
|
373 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
374 |
phase="normal")
|
|
375 |
self.assertEquals(context.get_refs_with_no_output(),[])
|
|
376 |
self.assertEquals(context.get_refs_with_no_output(['']),[''])
|
|
377 |
|
|
378 |
context.changed_refs = ['foo.bar',
|
|
379 |
'foo.two',
|
|
380 |
'foo.three']
|
|
381 |
|
|
382 |
self.assertEquals(context.get_refs_with_no_output(),['foo.bar',
|
|
383 |
'foo.three',
|
|
384 |
'foo.two'])
|
|
385 |
mi = MockImpl({})
|
|
386 |
mi.refs = ['foo.bar','nonno.noo','foo.three']
|
|
387 |
context.add_file('add1.txt', implementation=mi)
|
|
388 |
context.add_file('foo/add2.txt', implementation=None)
|
|
389 |
|
|
390 |
self.assertEquals(context.get_refs_with_no_output(),['foo.two'])
|
|
391 |
context.changed_refs = ['foo.bar',
|
|
392 |
'foo.three']
|
|
393 |
self.assertEquals(context.get_refs_with_no_output(),[])
|
|
394 |
mi.refs = []
|
|
395 |
self.assertEquals(context.get_refs_with_no_output(),['foo.bar',
|
|
396 |
'foo.three'])
|
|
397 |
mi.refs = None
|
|
398 |
self.assertEquals(context.get_refs_with_no_output(),['foo.bar',
|
|
399 |
'foo.three'])
|
|
400 |
|
|
401 |
def test_merged_context_get_changed_refs_intersect(self):
|
|
402 |
config = api.Configuration()
|
|
403 |
context1 = plugin.GenerationContext(configuration=config,
|
|
404 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
405 |
phase="normal")
|
|
406 |
context2 = plugin.GenerationContext(configuration=config,
|
|
407 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
408 |
phase="normal")
|
|
409 |
|
|
410 |
context1.changed_refs = ['foo.bar',
|
|
411 |
'foo.two',
|
|
412 |
'foo.three']
|
|
413 |
context2.changed_refs = ['foo.bar',
|
|
414 |
'foo.two1']
|
|
415 |
outs = plugin.MergedContext([context1,context2])
|
|
416 |
self.assertEquals(sorted(outs.get_changed_refs(operation='union')),
|
|
417 |
sorted(['foo.two1',
|
|
418 |
'foo.bar',
|
|
419 |
'foo.two',
|
|
420 |
'foo.three']))
|
|
421 |
self.assertEquals(outs.get_changed_refs(operation='intersection'), ['foo.bar'])
|
|
422 |
self.assertEquals(sorted(outs.get_changed_refs(operation='difference')), sorted(['foo.three',
|
|
423 |
'foo.two']))
|
|
424 |
self.assertEquals(sorted(outs.get_changed_refs(operation='symmetric_difference')), sorted(['foo.two1',
|
|
425 |
'foo.three',
|
|
426 |
'foo.two']))
|
|
427 |
|
|
428 |
def test_generation_get_refs_no_output_with_two_contexts(self):
|
|
429 |
config = api.Configuration()
|
|
430 |
context1 = plugin.GenerationContext(configuration=config,
|
|
431 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
432 |
phase="normal")
|
|
433 |
context2 = plugin.GenerationContext(configuration=config,
|
|
434 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
435 |
phase="normal")
|
|
436 |
|
|
437 |
context1.changed_refs = ['foo.bar',
|
|
438 |
'foo.two',
|
|
439 |
'foo.three']
|
|
440 |
context2.changed_refs = ['foo.bar1',
|
|
441 |
'foo.two1']
|
|
442 |
|
|
443 |
|
|
444 |
mi1 = MockImpl({})
|
|
445 |
mi1.refs = ['foo.bar','nonno.noo','foo.three']
|
|
446 |
mi2 = MockImpl({})
|
|
447 |
mi2.refs = ['foo.bar1']
|
|
448 |
context1.add_file('add1.txt', implementation=mi1)
|
|
449 |
context1.add_file('foo/add2.txt', implementation=None)
|
|
450 |
context2.add_file('add2.txt', implementation=mi2)
|
|
451 |
outs = plugin.MergedContext([context1,context2])
|
|
452 |
self.assertEquals(outs.get_refs_with_no_output(), ['foo.two', 'foo.two1'])
|
|
453 |
self.assertEquals(outs.get_refs_with_no_output(['foo.two']), ['foo.two'])
|
|
454 |
self.assertEquals(outs.get_refs_with_no_output(['foo.bar']), [])
|
|
455 |
|
|
456 |
def test_generation_get_refs_with_no_implementation(self):
|
|
457 |
config = api.Configuration()
|
|
458 |
context1 = plugin.GenerationContext(configuration=config,
|
|
459 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
460 |
phase="normal")
|
|
461 |
context2 = plugin.GenerationContext(configuration=config,
|
|
462 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
463 |
phase="normal")
|
|
464 |
|
|
465 |
context1.changed_refs = ['foo.bar',
|
|
466 |
'foo.two',
|
|
467 |
'foo.three']
|
|
468 |
context2.changed_refs = ['foo.bar1',
|
|
469 |
'foo.two1']
|
|
470 |
|
|
471 |
|
|
472 |
mi1 = MockImpl({})
|
|
473 |
mi1.ref = 'mi1'
|
|
474 |
mi1.refs = ['foo.bar','nonno.noo','foo.three']
|
|
475 |
mi2 = MockImpl({})
|
|
476 |
mi2.ref = 'mi2'
|
|
477 |
mi2.refs = ['foo.bar1']
|
|
478 |
context1.impl_set.add(mi1)
|
|
479 |
context2.impl_set.add(mi2)
|
|
480 |
outs = plugin.MergedContext([context1,context2])
|
|
481 |
self.assertEquals(outs.get_refs_with_no_implementation(), ['foo.two', 'foo.two1'])
|
|
482 |
self.assertEquals(outs.get_refs_with_no_implementation(['foo.bar']), [])
|
|
483 |
self.assertEquals(outs.get_refs_with_no_implementation(['foo.two', 'foo.bar1']), ['foo.two'])
|
|
484 |
|
|
485 |
|
|
486 |
def test_context_data_grep_log(self):
|
|
487 |
context = plugin.GenerationContext()
|
|
488 |
context.log = ['foo bar',
|
|
489 |
'foo faa',
|
|
490 |
'jee jee jehu']
|
|
491 |
self.assertEquals(context.grep_log('jee'), [(2,'jee jee jehu')])
|
|
492 |
|
4
|
493 |
def test_context_pickle(self):
|
|
494 |
remove_if_exists(os.path.join(ROOT_PATH,'temp'))
|
|
495 |
os.mkdir(os.path.join(ROOT_PATH, 'temp'))
|
|
496 |
|
|
497 |
config = api.Configuration()
|
|
498 |
config.create_feature('feature')
|
|
499 |
context = plugin.GenerationContext(configuration=config,
|
|
500 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
501 |
phase="normal")
|
|
502 |
|
|
503 |
dfile = open(os.path.join(ROOT_PATH,'temp/out_gencontext.dat'), 'w')
|
|
504 |
pickle.dump(context, dfile)
|
|
505 |
dfile.close()
|
|
506 |
dfile = open(os.path.join(ROOT_PATH,'temp/out_gencontext.dat'))
|
|
507 |
context2 = pickle.load(dfile)
|
|
508 |
self.assertEquals(context2.configuration.path, context.configuration.path)
|
|
509 |
|
|
510 |
def test_context_with_project_pickle(self):
|
|
511 |
remove_if_exists(os.path.join(ROOT_PATH,'temp'))
|
|
512 |
os.mkdir(os.path.join(ROOT_PATH, 'temp'))
|
|
513 |
prj = api.Project(api.Storage(""))
|
|
514 |
config = api.Configuration()
|
|
515 |
config.create_feature('feature')
|
|
516 |
prj.add_configuration(config, True)
|
|
517 |
context = plugin.GenerationContext(configuration=config,
|
|
518 |
output=os.path.join(ROOT_PATH, 'temp'),
|
|
519 |
phase="normal")
|
|
520 |
|
|
521 |
dfile = open(os.path.join(ROOT_PATH,'temp/out_gencontext2.dat'), 'w')
|
|
522 |
pickle.dump(context, dfile)
|
|
523 |
dfile.close()
|
|
524 |
dfile = open(os.path.join(ROOT_PATH,'temp/out_gencontext2.dat'))
|
|
525 |
context2 = pickle.load(dfile)
|
|
526 |
self.assertEquals(context2.configuration.path, context.configuration.path)
|
|
527 |
|
|
528 |
|
0
|
529 |
class TestPluginImplBase(unittest.TestCase):
|
|
530 |
def setUp(self):
|
|
531 |
pass
|
|
532 |
|
|
533 |
def test_implbase_add_tags(self):
|
|
534 |
impl = plugin.ImplBase('test',None)
|
|
535 |
impl.set_tags({'target': ['test', 'foo']})
|
|
536 |
self.assertEquals(impl.get_tags()['target'],['test','foo'])
|
|
537 |
#self.assertEquals(impl.has_tag({}, policy='OR'), True)
|
|
538 |
self.assertEquals(impl.has_tag({'target': ['test']}, policy='OR'), True)
|
|
539 |
self.assertEquals(impl.has_tag({'target': ['test']}, policy='AND'), True)
|
|
540 |
self.assertEquals(impl.has_tag({'target': ['foo']}, policy='OR'), True)
|
|
541 |
self.assertEquals(impl.has_tag({'target': ['foo']}, policy='AND'), True)
|
|
542 |
self.assertEquals(impl.has_tag({'target': ['test','foo']}, policy='OR'), True)
|
|
543 |
self.assertEquals(impl.has_tag({'target': ['test','foo']}, policy='AND'), True)
|
|
544 |
self.assertEquals(impl.has_tag({'target': ['test2','foo']}, policy='OR'), True)
|
|
545 |
self.assertEquals(impl.has_tag({'target': ['test2','foo']}, policy='AND'), False)
|
|
546 |
self.assertEquals(impl.has_tag({'foo': ['foo']}, policy='OR'), False)
|
|
547 |
self.assertEquals(impl.has_tag({'foo': ['foo']}, policy='AND'), False)
|
|
548 |
self.assertEquals(impl.has_tag({'target': ['foo'], 'foo':['bar']}, policy='AND'), False)
|
|
549 |
self.assertEquals(impl.has_tag({'target': ['foo'], 'foo':['bar']}, policy='OR'), True)
|
3
|
550 |
|
|
551 |
def test_implbase_output(self):
|
|
552 |
str = api.Storage(utils.relpath(ROOT_PATH))
|
|
553 |
config = api.Configuration('foo')
|
|
554 |
config.storage = str
|
|
555 |
impl = plugin.ImplBase('foo.implml', config)
|
|
556 |
self.assertEquals(impl.output, '')
|
|
557 |
impl.plugin_output = 'test'
|
|
558 |
self.assertEquals(impl.output, 'test')
|
|
559 |
impl.set_output_root('foobar')
|
|
560 |
self.assertEquals(impl.output, 'foobar/test')
|
|
561 |
impl.set_output_root('/foobar')
|
|
562 |
self.assertEquals(impl.output, '/foobar/test')
|
|
563 |
|
|
564 |
self.assertEquals(impl.path, 'foo.implml')
|
|
565 |
self.assertEquals(impl.abspath, os.path.abspath(os.path.join(ROOT_PATH,'foo.implml')))
|
|
566 |
|
|
567 |
|
0
|
568 |
def test_implbase_tags_with_refs(self):
|
|
569 |
config = MockConfiguration({}, features = {
|
|
570 |
'Foo.Bar' : 'foobar',
|
|
571 |
'Foo.Baz' : 'foobaz',
|
|
572 |
'Feature.TagName' : 'tagname',
|
|
573 |
'Feature.TagValue' : 'tagvalue',
|
|
574 |
})
|
|
575 |
|
|
576 |
impl = plugin.ImplBase('test', config)
|
|
577 |
impl.set_tags({
|
|
578 |
'test' : ['${Foo.Bar}', 'foo', 'bar', '${Foo.Bar} and ${Foo.Baz}'],
|
|
579 |
'${Feature.TagName}': ['${Feature.TagValue}']})
|
|
580 |
|
|
581 |
expected = {
|
|
582 |
'test': ['foobar', 'foo', 'bar', 'foobar and foobaz'],
|
|
583 |
'tagname': ['tagvalue'],
|
|
584 |
}
|
|
585 |
self.assertEquals(impl.get_tags(), expected)
|
|
586 |
|
|
587 |
def test_has_ref(self):
|
|
588 |
impl = plugin.ImplBase('test', None)
|
|
589 |
self.assertEquals(impl.has_ref('Foo.Bar'), None)
|
|
590 |
|
|
591 |
impl.get_refs = lambda: ['Foo.Bar', 'Xyz']
|
|
592 |
|
|
593 |
# Test using different supported parameter types
|
|
594 |
self.assertTrue(impl.has_ref('Foo.Bar'))
|
|
595 |
self.assertTrue(impl.has_ref(['Foo.Bar']))
|
|
596 |
self.assertTrue(impl.has_ref(('Foo.Bar',)))
|
|
597 |
|
|
598 |
# Impl uses the exact given ref
|
|
599 |
self.assertTrue(impl.has_ref('Foo.Bar'))
|
|
600 |
self.assertTrue(impl.has_ref('Xyz'))
|
|
601 |
|
|
602 |
# Impl uses the given ref's parent ref
|
|
603 |
self.assertTrue(impl.has_ref('Foo.Bar.Baz'))
|
|
604 |
self.assertTrue(impl.has_ref('Xyz.Zyx'))
|
|
605 |
|
|
606 |
# Impl does not use the entire parent ref of 'Foo.Bar', only the
|
|
607 |
# 'Bar' sub-ref
|
|
608 |
self.assertFalse(impl.has_ref('Foo'))
|
|
609 |
|
|
610 |
# Various refs almost matching a specified ref
|
|
611 |
self.assertFalse(impl.has_ref('Fo'))
|
|
612 |
self.assertFalse(impl.has_ref('Fog'))
|
|
613 |
self.assertFalse(impl.has_ref('Food'))
|
|
614 |
self.assertFalse(impl.has_ref('Foo.Ba'))
|
|
615 |
self.assertFalse(impl.has_ref('Foo.Bag'))
|
|
616 |
self.assertFalse(impl.has_ref('Foo.Bard'))
|
|
617 |
|
|
618 |
# Various refs not at all in the impl's ref list
|
|
619 |
self.assertFalse(impl.has_ref('Yay'))
|
|
620 |
self.assertFalse(impl.has_ref(['Yay', 'Fhtagn']))
|
|
621 |
|
|
622 |
# One of the refs in the given list matches
|
|
623 |
self.assertTrue(impl.has_ref(['Yay', 'Fhtagn', 'Foo.Bar']))
|
|
624 |
self.assertTrue(impl.has_ref(['Yay', 'Foo.Bar.Baz', 'Fhtagn']))
|
|
625 |
self.assertTrue(impl.has_ref(['Yay', 'Xyz', 'Fhtagn']))
|
|
626 |
|
|
627 |
|
3
|
628 |
class TestPlugin(plugin.ImplBase):
|
|
629 |
def __init__(self, ref):
|
|
630 |
super(TestPlugin, self).__init__(ref, None)
|
|
631 |
self.refs = None
|
0
|
632 |
|
3
|
633 |
def get_refs(self):
|
|
634 |
return self.refs
|
|
635 |
|
|
636 |
class TestPluginImplSet(unittest.TestCase):
|
0
|
637 |
def test_add_implementation_and_list(self):
|
3
|
638 |
iset= plugin.ImplSet()
|
0
|
639 |
imp1 = plugin.ImplBase("implml/test.content",None)
|
|
640 |
imp2a = plugin.ImplBase("implml/copy.content",None)
|
|
641 |
imp2b = plugin.ImplBase("implml/copy.content",None)
|
3
|
642 |
iset.add_implementation(imp1)
|
|
643 |
iset.add_implementation(imp2a)
|
|
644 |
iset.add_implementation(imp2b)
|
|
645 |
self.assertEquals(sorted(iset.list_implementation()),
|
0
|
646 |
sorted(['implml/test.content',
|
|
647 |
'implml/copy.content']))
|
|
648 |
|
3
|
649 |
def test_add_implementation_and_generate(self):
|
|
650 |
iset = plugin.ImplSet()
|
|
651 |
imp1 = SimpleImpl("implml/test1.content", None)
|
|
652 |
imp1.outputfile = 'test/foo.txt'
|
|
653 |
imp2a = SimpleImpl("implml/test2.content", None)
|
|
654 |
imp2b = SimpleImpl("implml/test3.content", None)
|
|
655 |
iset.add_implementation(imp1)
|
|
656 |
iset.add_implementation(imp2a)
|
|
657 |
iset.add_implementation(imp2b)
|
|
658 |
context = plugin.GenerationContext(output="temp")
|
|
659 |
iset.generate(context)
|
|
660 |
self.assertEquals(sorted(context.executed_impls), sorted([imp1, imp2a, imp2b]))
|
|
661 |
self.assertEquals(context.generation_output[0].name, 'temp/test/foo.txt')
|
|
662 |
self.assertTrue(os.path.exists(context.generation_output[0].name))
|
|
663 |
self.assertEquals(context.generation_output[0].implementation,imp1)
|
|
664 |
|
|
665 |
|
|
666 |
def test__generate_with_exception(self):
|
|
667 |
def generate_exception(*args):
|
|
668 |
raise Exception("test exception %s" % args)
|
|
669 |
|
|
670 |
iset = plugin.ImplSet()
|
|
671 |
imp1 = SimpleImpl("implml/test1.content", None)
|
|
672 |
imp1.outputfile = 'test/foo.txt'
|
|
673 |
imp2a = SimpleImpl("implml/test2.content", None)
|
|
674 |
imp2a.generate = generate_exception
|
|
675 |
iset.add_implementation(imp1)
|
|
676 |
iset.add_implementation(imp2a)
|
|
677 |
context = plugin.GenerationContext(output="temp")
|
|
678 |
iset.generate(context)
|
|
679 |
self.assertEquals(sorted(context.executed_impls), sorted([imp1, imp2a]))
|
|
680 |
self.assertEquals(context.generation_output[1].type, 'exception')
|
|
681 |
self.assertEquals(context.generation_output[1].name, 'exception from implml/test2.content')
|
|
682 |
self.assertEquals(context.generation_output[1].implementation, imp2a)
|
|
683 |
|
0
|
684 |
def test_add_implementation_and_get_implementations_by_file(self):
|
3
|
685 |
iset = plugin.ImplSet()
|
0
|
686 |
imp1 = plugin.ImplBase("implml/test.content",None)
|
|
687 |
imp2a = plugin.ImplBase("implml/copy.content",None)
|
|
688 |
imp2b = plugin.ImplBase("implml/copy.content",None)
|
3
|
689 |
iset.add_implementation(imp1)
|
|
690 |
iset.add_implementation(imp2a)
|
|
691 |
iset.add_implementation(imp2b)
|
|
692 |
self.assertEquals(iset.get_implementations_by_file("implml/test.content"), [imp1])
|
|
693 |
self.assertEquals(sorted(iset.get_implementations_by_file("implml/copy.content")),
|
0
|
694 |
sorted([imp2a, imp2b]))
|
|
695 |
|
|
696 |
def test_add_implementation_and_remove_implementation(self):
|
3
|
697 |
iset = plugin.ImplSet()
|
0
|
698 |
imp1 = plugin.ImplBase("implml/test.content",None)
|
|
699 |
imp2a = plugin.ImplBase("implml/copy.content",None)
|
|
700 |
imp2b = plugin.ImplBase("implml/copy.content",None)
|
3
|
701 |
iset.add_implementation(imp1)
|
|
702 |
iset.add_implementation(imp2a)
|
|
703 |
iset.add_implementation(imp2b)
|
|
704 |
iset.remove_implementation("implml/test.content")
|
|
705 |
self.assertEquals(len(iset.list_implementation()),1)
|
|
706 |
self.assertEquals(iset.list_implementation()[0],"implml/copy.content")
|
0
|
707 |
|
|
708 |
def test_add_implementation_and_remove_all(self):
|
3
|
709 |
iset = plugin.ImplSet()
|
0
|
710 |
imp1 = plugin.ImplBase("implml/test.content",None)
|
|
711 |
imp2a = plugin.ImplBase("implml/copy.content",None)
|
|
712 |
imp2b = plugin.ImplBase("implml/copy.content",None)
|
|
713 |
imp3 = plugin.ImplBase("implml/foo.content",None)
|
3
|
714 |
iset.add_implementation(imp1)
|
|
715 |
iset.add_implementation(imp2a)
|
|
716 |
iset.add_implementation(imp2b)
|
|
717 |
iset.add_implementation(imp3)
|
|
718 |
for implref in iset.list_implementation():
|
|
719 |
iset.remove_implementation(implref)
|
|
720 |
self.assertEquals(len(iset.list_implementation()),0)
|
0
|
721 |
|
|
722 |
def test_create_impl_set(self):
|
|
723 |
plugin.create_impl_set('',None);
|
|
724 |
pass
|
|
725 |
|
|
726 |
def test_add_implementation_find_with_tags(self):
|
3
|
727 |
def impl_list(impl_iterable):
|
|
728 |
return sorted(list(impl_iterable), key=lambda impl: impl.ref)
|
|
729 |
|
|
730 |
iset = plugin.ImplSet()
|
|
731 |
imp1 = TestPlugin("implml/test.content")
|
|
732 |
imp2 = TestPlugin("implml/copy.content")
|
|
733 |
imp3 = TestPlugin("implml/foo.content")
|
0
|
734 |
imp1.set_tags({'target': ['core','rofs2','rofs3']})
|
|
735 |
imp2.set_tags({'target': ['rofs3','uda']})
|
|
736 |
imp3.set_tags({'target': ['mmc','uda']})
|
3
|
737 |
iset.add_implementation(imp1)
|
|
738 |
iset.add_implementation(imp2)
|
|
739 |
iset.add_implementation(imp3)
|
|
740 |
self.assertEquals(impl_list(iset.filter_implementations(tags={'target' : ['rofs3']})),
|
|
741 |
impl_list([imp1,imp2]))
|
|
742 |
self.assertEquals(impl_list(iset.filter_implementations(tags={'target' : ['uda']})),
|
|
743 |
impl_list([imp2,imp3]))
|
|
744 |
self.assertEquals(impl_list(iset.filter_implementations(tags={'target' : ['mmc','uda']}, policy='AND')),
|
|
745 |
impl_list([imp3]))
|
|
746 |
self.assertEquals(impl_list(iset.filter_implementations(tags={'target' : ['mmc','uda']}, policy='OR')),
|
|
747 |
impl_list([imp2, imp3]))
|
|
748 |
cont = iset.filter_implementations(tags={'target' : ['core']}) | iset.filter_implementations(tags={'target' : ['mmc']})
|
0
|
749 |
self.assertEquals(len(cont),2)
|
3
|
750 |
self.assertEquals(impl_list(cont), impl_list([imp1,imp3]))
|
0
|
751 |
|
3
|
752 |
cont = iset.filter_implementations(tags={'target' : ['rofs3']}) & iset.filter_implementations(tags={'target' : ['uda']})
|
0
|
753 |
self.assertEquals(len(cont),1)
|
3
|
754 |
self.assertEquals(impl_list(cont), impl_list([imp2]))
|
0
|
755 |
|
|
756 |
def test_pre_impl_filter(self):
|
|
757 |
resources = [
|
|
758 |
"foo.txt",
|
|
759 |
".hidden_file",
|
|
760 |
".test/test.txt",
|
|
761 |
"layer1/implml/.hidden",
|
|
762 |
"layer1/implml/test.crml",
|
|
763 |
"layer1/implml/test3.gcfml",
|
|
764 |
"layer1/implml/.svn/text-base/test.crml.svn-base",
|
|
765 |
"layer1/implml/subdir/test5.crml",
|
|
766 |
"layer1/implml/subdir/test6.ruleml",
|
|
767 |
"layer1/implml/subdir/.scripts/test6_ruleml.py",
|
|
768 |
]
|
|
769 |
|
|
770 |
expected = [
|
|
771 |
"foo.txt",
|
|
772 |
"layer1/implml/test.crml",
|
|
773 |
"layer1/implml/test3.gcfml",
|
|
774 |
"layer1/implml/subdir/test5.crml",
|
|
775 |
"layer1/implml/subdir/test6.ruleml",
|
|
776 |
]
|
|
777 |
|
|
778 |
self.assertEquals(expected, plugin.pre_filter_impls(resources))
|
|
779 |
|
|
780 |
# Test with backslashes
|
|
781 |
resources = map(lambda path: path.replace('/', '\\'), resources)
|
|
782 |
expected = map(lambda path: path.replace('/', '\\'), expected)
|
|
783 |
self.assertEquals(expected, plugin.pre_filter_impls(resources))
|
|
784 |
|
3
|
785 |
def test_get_implemented_refs(self):
|
|
786 |
|
|
787 |
iset = plugin.ImplSet()
|
|
788 |
imp1 = TestPlugin('imp1')
|
|
789 |
imp2 = TestPlugin('imp2')
|
|
790 |
imp3 = TestPlugin('imp3')
|
|
791 |
iset.add_implementation(imp1)
|
|
792 |
iset.add_implementation(imp2)
|
|
793 |
iset.add_implementation(imp3)
|
|
794 |
imp1.refs = ['fea.child1', 'fea.child2']
|
|
795 |
imp2.refs = ['fea.setting1']
|
|
796 |
imp3.refs = ['foo.bar']
|
|
797 |
self.assertEquals(sorted(iset.get_implemented_refs()), sorted(['fea.child1',
|
|
798 |
'fea.child2',
|
|
799 |
'fea.setting1',
|
|
800 |
'foo.bar']))
|
|
801 |
|
|
802 |
def test_get_implementations_with_ref(self):
|
|
803 |
|
|
804 |
iset = plugin.ImplSet()
|
|
805 |
imp1 = TestPlugin('implml1')
|
|
806 |
imp2 = TestPlugin('implml2')
|
|
807 |
imp3 = TestPlugin('implml3')
|
|
808 |
imp4 = TestPlugin('implml3')
|
|
809 |
iset.add_implementation(imp1)
|
|
810 |
iset.add_implementation(imp2)
|
|
811 |
iset.add_implementation(imp3)
|
|
812 |
iset.add_implementation(imp4)
|
|
813 |
imp1.refs = ['fea.child1', 'fea.child2']
|
|
814 |
imp2.refs = ['foo.bar', 'fea.setting1']
|
|
815 |
imp3.refs = ['foo.bar']
|
|
816 |
self.assertEquals(iset.get_implementations_with_ref('fea.child1'), [imp1])
|
|
817 |
self.assertEquals(iset.get_implementations_with_ref('fea.setting1'), [imp2])
|
|
818 |
self.assertEquals(iset.get_implementations_with_ref('foo.bar'), [imp2, imp3])
|
0
|
819 |
|
|
820 |
class TestPluginImplSetCopy(unittest.TestCase):
|
|
821 |
class TestImpl(plugin.ImplBase):
|
|
822 |
pass # No default invocation phase specified, should be 'normal'
|
|
823 |
class PreImpl(plugin.ImplBase):
|
|
824 |
DEFAULT_INVOCATION_PHASE = 'pre'
|
|
825 |
class NormalImpl(plugin.ImplBase):
|
|
826 |
DEFAULT_INVOCATION_PHASE = 'normal'
|
|
827 |
class PostImpl(plugin.ImplBase):
|
|
828 |
DEFAULT_INVOCATION_PHASE = 'post'
|
|
829 |
|
|
830 |
def setUp(self):
|
|
831 |
plugin.ImplFactory.set_reader_classes_override(MOCK_READER_CLASSES)
|
|
832 |
|
|
833 |
def tearDown(self):
|
|
834 |
plugin.ImplFactory.set_reader_classes_override(None)
|
|
835 |
|
|
836 |
def _get_impl_container(self):
|
|
837 |
impl_files = ['layer1/implml/single1.implml',
|
|
838 |
'layer1/implml/single2.implml',
|
|
839 |
'layer1/implml/single3.implml',
|
|
840 |
'layer1/implml/multi1.implml',
|
|
841 |
'layer1/implml/multi2.implml']
|
|
842 |
return plugin.create_impl_set(impl_files, mock_config)
|
|
843 |
|
|
844 |
|
3
|
845 |
def test_get_test_impl_iset(self):
|
|
846 |
iset = self._get_impl_container()
|
0
|
847 |
# There are 5 ImplML files
|
3
|
848 |
self.assertEquals(len(iset.list_implementation()), 5)
|
0
|
849 |
# ...but two of them contain 3 implementations each
|
3
|
850 |
self.assertEquals(len(iset), 5)
|
0
|
851 |
|
|
852 |
def _get_phase_test_impl_container(self):
|
|
853 |
return plugin.ImplSet([
|
|
854 |
self.TestImpl('foo.test', None),
|
|
855 |
self.NormalImpl('foo.norm', None),
|
|
856 |
self.PreImpl('foo.pre', None),
|
|
857 |
self.PostImpl('test.post', None),
|
|
858 |
self.PostImpl('foo.post', None),
|
|
859 |
])
|
|
860 |
|
3
|
861 |
def test_get_phase_test_impl_iset(self):
|
|
862 |
iset = self._get_phase_test_impl_container()
|
|
863 |
self.assertEquals(5, len(iset))
|
|
864 |
self.assertEquals(len(iset.list_implementation()), 5)
|
0
|
865 |
|
|
866 |
def check(filename, phase):
|
3
|
867 |
impls = iset.get_implementations_by_file(filename)
|
0
|
868 |
self.assertEquals(1, len(impls))
|
|
869 |
impl = impls[0]
|
|
870 |
self.assertEquals(impl.ref, filename)
|
|
871 |
self.assertEquals(impl.invocation_phase(), phase)
|
|
872 |
check('foo.test', 'normal')
|
|
873 |
check('foo.norm', 'normal')
|
|
874 |
check('foo.pre', 'pre')
|
|
875 |
check('test.post', 'post')
|
|
876 |
check('foo.post', 'post')
|
|
877 |
|
3
|
878 |
return iset
|
0
|
879 |
|
|
880 |
def test_create_impl_set(self):
|
3
|
881 |
iset = self._get_impl_container()
|
0
|
882 |
# There are 5 ImplML files
|
3
|
883 |
self.assertEquals(len(iset.list_implementation()), 5)
|
0
|
884 |
# ...but two of them contain 3 implementations each
|
3
|
885 |
self.assertEquals(len(iset), 5)
|
0
|
886 |
|
|
887 |
def test_invocation_phases(self):
|
3
|
888 |
iset = self._get_phase_test_impl_container()
|
|
889 |
phases = iset.invocation_phases()
|
0
|
890 |
self.assertEquals(phases,['pre','normal','post'])
|
|
891 |
|
|
892 |
def test_copy(self):
|
3
|
893 |
iset = self._get_impl_container()
|
|
894 |
newcontainer = iset.copy()
|
|
895 |
self.assertTrue(newcontainer is not iset)
|
0
|
896 |
self.assertEquals(len(newcontainer), 5)
|
|
897 |
|
|
898 |
def test_execute_generate(self):
|
3
|
899 |
iset = self._get_impl_container()
|
|
900 |
iset.execute(iset, 'generate')
|
0
|
901 |
actual_impls = []
|
3
|
902 |
for impl in iset:
|
0
|
903 |
if isinstance(impl, plugin.ImplContainer):
|
|
904 |
actual_impls += impl.get_all_implementations()
|
|
905 |
else:
|
|
906 |
actual_impls.append(impl)
|
|
907 |
for impl in actual_impls:
|
|
908 |
self.assertTrue(impl.generate_invoked)
|
|
909 |
|
|
910 |
def test_impl_container_generate(self):
|
3
|
911 |
iset = self._get_impl_container()
|
0
|
912 |
context = plugin.GenerationContext()
|
|
913 |
context.history = ""
|
|
914 |
context.objects = []
|
3
|
915 |
iset.generate(context)
|
0
|
916 |
self.assertEquals(len(context.objects), 9)
|
|
917 |
actual_impls = []
|
3
|
918 |
for impl in iset:
|
0
|
919 |
if isinstance(impl, plugin.ImplContainer):
|
|
920 |
actual_impls += impl.get_all_implementations()
|
|
921 |
else:
|
|
922 |
actual_impls.append(impl)
|
|
923 |
for impl in actual_impls:
|
|
924 |
self.assertTrue(impl.generate_invoked)
|
|
925 |
|
|
926 |
def test_filter_all(self):
|
3
|
927 |
iset = self._get_impl_container()
|
|
928 |
impl_list = iset.filter_implementations()
|
0
|
929 |
self.assertEquals(len(impl_list), 5)
|
|
930 |
|
|
931 |
def test_filter_for_pre_phase(self):
|
3
|
932 |
iset = self._get_phase_test_impl_container()
|
|
933 |
impl_list = list(iset.filter_implementations(phase='pre'))
|
0
|
934 |
self.assertEquals(len(impl_list), 1)
|
|
935 |
self.assertEquals(impl_list[0].invocation_phase(), 'pre')
|
|
936 |
self.assertEquals(impl_list[0].ref, 'foo.pre')
|
|
937 |
|
|
938 |
def test_filter_for_normal_phase(self):
|
3
|
939 |
iset = self._get_phase_test_impl_container()
|
|
940 |
impl_list = list(iset.filter_implementations(phase='normal'))
|
0
|
941 |
self.assertEquals(len(impl_list), 2)
|
|
942 |
self.assertEquals(impl_list[0].invocation_phase(), 'normal')
|
|
943 |
self.assertEquals(impl_list[1].invocation_phase(), 'normal')
|
|
944 |
|
|
945 |
def test_filter_for_post_phase(self):
|
3
|
946 |
iset = self._get_phase_test_impl_container()
|
|
947 |
impl_list = list(iset.filter_implementations(phase='post'))
|
0
|
948 |
self.assertEquals(len(impl_list), 2)
|
|
949 |
self.assertEquals(impl_list[0].invocation_phase(), 'post')
|
|
950 |
self.assertEquals(impl_list[1].invocation_phase(), 'post')
|
|
951 |
|
|
952 |
|
|
953 |
class TestPluginImplSettings(unittest.TestCase):
|
|
954 |
class Test1Impl(plugin.ImplBase):
|
|
955 |
IMPL_TYPE_ID = "test1"
|
|
956 |
class Test2Impl(plugin.ImplBase):
|
|
957 |
IMPL_TYPE_ID = "test2"
|
|
958 |
class Test3Impl(plugin.ImplBase):
|
|
959 |
IMPL_TYPE_ID = "test3"
|
|
960 |
|
|
961 |
def test_plugin_settings(self):
|
|
962 |
settings.SettingsFactory.cone_parser().read([os.path.join(ROOT_PATH,'test_defaults.cfg')])
|
|
963 |
impl = TestPluginImplSettings.Test1Impl("",None)
|
3
|
964 |
self.assertEquals(impl.output_root, '')
|
0
|
965 |
self.assertEquals(impl.output_subdir, '')
|
|
966 |
impl.output_subdir = 'foobar'
|
|
967 |
self.assertEquals(impl.get_tags(), {})
|
3
|
968 |
self.assertEquals(impl.output, 'foobar')
|
0
|
969 |
|
|
970 |
impl = TestPluginImplSettings.Test2Impl("",None)
|
|
971 |
self.assertEquals(impl.output_subdir, '')
|
|
972 |
|
|
973 |
|
|
974 |
|
|
975 |
class TestReaders(unittest.TestCase):
|
|
976 |
|
|
977 |
def setUp(self):
|
|
978 |
plugin.ImplFactory.set_reader_classes_override(MOCK_READER_CLASSES)
|
|
979 |
|
|
980 |
def tearDown(self):
|
|
981 |
plugin.ImplFactory.set_reader_classes_override(None)
|
|
982 |
|
|
983 |
def assert_namespace_list_equals(self, resource_ref, expected_namespaces):
|
|
984 |
self.assertEquals(
|
|
985 |
expected_namespaces,
|
|
986 |
_plugin_reader.ImplReader._get_namespaces(mock_config.get_doc(resource_ref)))
|
|
987 |
|
|
988 |
def test_get_needed_reader_classes(self):
|
|
989 |
self.assert_namespace_list_equals('layer1/implml/none.implml', [])
|
|
990 |
|
|
991 |
self.assert_namespace_list_equals('layer1/implml/single1.implml',
|
|
992 |
['http://www.test.com/xml/1'])
|
|
993 |
|
|
994 |
self.assert_namespace_list_equals('layer1/implml/single2.implml',
|
|
995 |
['http://www.test.com/xml/2'])
|
|
996 |
|
|
997 |
self.assert_namespace_list_equals('layer1/implml/multi1.implml',
|
|
998 |
['http://www.symbianfoundation.org/xml/implml/1',
|
|
999 |
'http://www.test.com/xml/1',
|
|
1000 |
'http://www.test.com/xml/2',
|
|
1001 |
'http://www.test.com/xml/3'])
|
|
1002 |
|
|
1003 |
self.assert_namespace_list_equals('layer1/implml/multi2.implml',
|
|
1004 |
['http://www.symbianfoundation.org/xml/implml/1',
|
|
1005 |
'http://www.test.com/xml/1',
|
|
1006 |
'http://www.test.com/xml/2',
|
|
1007 |
'http://www.test.com/xml/3'])
|
|
1008 |
|
|
1009 |
self.assert_namespace_list_equals('layer1/implml/multi3.implml',
|
|
1010 |
['http://www.symbianfoundation.org/xml/implml/1',
|
|
1011 |
'http://www.test.com/xml/1',
|
|
1012 |
'http://www.test.com/xml/2'])
|
|
1013 |
|
|
1014 |
self.assert_namespace_list_equals('layer1/implml/unsupported1.implml',
|
|
1015 |
['http://www.test.com/xml/1',
|
|
1016 |
'http://www.test.com/xml/2',
|
|
1017 |
'http://www.test.com/xml/4'])
|
|
1018 |
|
|
1019 |
self.assert_namespace_list_equals('layer1/implml/unsupported2.implml',
|
|
1020 |
['http://www.test.com/xml/6',
|
|
1021 |
'http://www.test.com/xml/2',
|
|
1022 |
'http://www.test.com/xml/4'])
|
|
1023 |
|
|
1024 |
def assert_read_impls_equal(self, expected, resource_ref):
|
|
1025 |
actual = plugin.ImplFactory.get_impls_from_file(resource_ref, mock_config)
|
|
1026 |
if len(actual) == 1 and isinstance(actual[0], plugin.ImplContainer):
|
|
1027 |
actual = actual[0].get_all_implementations()
|
|
1028 |
self.assertEquals(expected, actual)
|
|
1029 |
|
|
1030 |
# # Assert that the implementations have the correct impl indices set
|
|
1031 |
# for i, impl in enumerate(actual):
|
|
1032 |
# self.assertEquals(i, impl.index, "Impl %r does not have the expected index %r (is %r)" % (impl, i, impl.index))
|
|
1033 |
|
|
1034 |
def test_get_impls_from_file(self):
|
|
1035 |
self.assert_read_impls_equal(
|
|
1036 |
[],
|
|
1037 |
'layer1/implml/none.implml')
|
|
1038 |
|
|
1039 |
file = 'layer1/implml/single1.implml'
|
|
1040 |
self.assert_read_impls_equal(
|
|
1041 |
[MockImpl(['MockReader1', file, {'x': '1'}, {'y': '2'}, {'z': '3'}])],
|
|
1042 |
file)
|
|
1043 |
|
|
1044 |
file = 'layer1/implml/single2.implml'
|
|
1045 |
self.assert_read_impls_equal(
|
|
1046 |
[MockImpl(['MockReader2', file])],
|
|
1047 |
file)
|
|
1048 |
|
|
1049 |
file = 'layer1/implml/single3.implml'
|
|
1050 |
self.assert_read_impls_equal(
|
|
1051 |
[MockImpl(['MockReader3', file, {'x': '1'}])],
|
|
1052 |
file)
|
|
1053 |
|
|
1054 |
file = 'layer1/implml/multi1.implml'
|
|
1055 |
self.assert_read_impls_equal(
|
|
1056 |
[MockImpl(['MockReader1', file, {'x': '1', 'y': '2'}]),
|
|
1057 |
MockImpl(['MockReader2', file, {'x': '10', 'y': '20'}]),
|
|
1058 |
MockImpl(['MockReader3', file, {'x': '100', 'y': '200'}, {'z': '300'}])],
|
|
1059 |
file)
|
|
1060 |
|
|
1061 |
file = 'layer1/implml/multi2.implml'
|
|
1062 |
self.assert_read_impls_equal(
|
|
1063 |
[MockImpl(['MockReader1', file, {'x': '1', 'y': '2'}]),
|
|
1064 |
MockImpl(['MockReader2', file, {'x': '10', 'y': '20'}]),
|
|
1065 |
MockImpl(['MockReader3', file, {'x': '100', 'y': '200'}, {'z': '300'}])],
|
|
1066 |
file)
|
|
1067 |
|
|
1068 |
file = 'layer1/implml/multi3.implml'
|
|
1069 |
self.assert_read_impls_equal(
|
|
1070 |
[MockImpl(['MockReader1', file, {'x': '1', 'y': '2'}]),
|
|
1071 |
MockImpl(['MockReader2', file, {'x': '1', 'y': '2'}]),
|
|
1072 |
MockImpl(['MockReader1', file, {'a': '1', 'b': '2'}]),
|
|
1073 |
MockImpl(['MockReader2', file, {'a': '1', 'b': '2'}]),],
|
|
1074 |
file)
|
|
1075 |
|
|
1076 |
|
|
1077 |
self.assert_read_impls_equal([], 'layer1/implml/unsupported1.implml')
|
|
1078 |
self.assert_read_impls_equal([], 'layer1/implml/unsupported2.implml')
|
|
1079 |
|
|
1080 |
self.assert_read_impls_equal([], 'layer1/implml/broken.implml')
|
|
1081 |
|
|
1082 |
def test_is_supported_impl_file(self):
|
|
1083 |
def check(filename, expected):
|
|
1084 |
self.assertEquals(expected, plugin.ImplFactory.is_supported_impl_file(filename))
|
|
1085 |
check('test.implml', True)
|
|
1086 |
check('layer/implml/test.implml', True)
|
|
1087 |
check('layer/implml/test.mock1ml', True)
|
|
1088 |
check('layer/implml/test.mock2ml', True)
|
|
1089 |
check('layer/implml/test.mock3ml', True)
|
|
1090 |
check('layer/implml/test.test3ml', True)
|
|
1091 |
check('layer/implml/test.dummyml', False)
|
|
1092 |
check('layer/implml/test.xml', False)
|
|
1093 |
check('layer/implml/test', False)
|
|
1094 |
check('layer/implml/test.IMPLML', True)
|
|
1095 |
check('layer/implml/test.ImplML', True)
|
|
1096 |
check('layer/implml/test.Mock1ML', True)
|
|
1097 |
|
|
1098 |
def test_read_all_impls(self):
|
|
1099 |
actual = list(plugin.get_impl_set(mock_config))
|
|
1100 |
actual_impls = []
|
|
1101 |
for impl in actual:
|
|
1102 |
if isinstance(impl, plugin.ImplContainer):
|
|
1103 |
actual_impls += impl.get_all_implementations()
|
|
1104 |
else:
|
|
1105 |
actual_impls.append(impl)
|
|
1106 |
|
|
1107 |
expected = [
|
|
1108 |
MockImpl(['MockReader1', 'layer1/implml/single1.implml', {'x': '1'}, {'y': '2'}, {'z': '3'}]),
|
|
1109 |
MockImpl(['MockReader2', 'layer1/implml/single2.implml']),
|
|
1110 |
MockImpl(['MockReader3', 'layer1/implml/single3.implml', {'x': '1'}]),
|
|
1111 |
|
|
1112 |
MockImpl(['MockReader1', 'layer1/implml/single1.mock1ml', {'x': '1'}, {'y': '2'}, {'z': '3'}]),
|
|
1113 |
MockImpl(['MockReader2', 'layer1/implml/single2.mock2ml']),
|
|
1114 |
MockImpl(['MockReader3', 'layer1/implml/single3.mock3ml', {'x': '1'}]),
|
|
1115 |
|
|
1116 |
MockImpl(['MockReader3', 'layer1/implml/single3.test3ml', {'x': '1'}]),
|
|
1117 |
|
|
1118 |
MockImpl(['MockReader1','layer1/implml/multi1.implml', {'y': '2', 'x': '1'}]),
|
|
1119 |
MockImpl(['MockReader2', 'layer1/implml/multi1.implml', {'y': '20', 'x': '10'}]),
|
|
1120 |
MockImpl(['MockReader3', 'layer1/implml/multi1.implml', {'y': '200', 'x': '100'}, {'z': '300'}]),
|
|
1121 |
|
|
1122 |
MockImpl(['MockReader1', 'layer1/implml/multi2.implml', {'x': '1', 'y': '2'}]),
|
|
1123 |
MockImpl(['MockReader2', 'layer1/implml/multi2.implml', {'x': '10', 'y': '20'}]),
|
|
1124 |
MockImpl(['MockReader3', 'layer1/implml/multi2.implml', {'x': '100', 'y': '200'}, {'z': '300'}]),
|
|
1125 |
|
|
1126 |
MockImpl(['MockReader1', 'layer1/implml/multi3.implml', {'x': '1', 'y': '2'}]),
|
|
1127 |
MockImpl(['MockReader2', 'layer1/implml/multi3.implml', {'x': '1', 'y': '2'}]),
|
|
1128 |
MockImpl(['MockReader1', 'layer1/implml/multi3.implml', {'a': '1', 'b': '2'}]),
|
|
1129 |
MockImpl(['MockReader2', 'layer1/implml/multi3.implml', {'a': '1', 'b': '2'}]),
|
|
1130 |
]
|
|
1131 |
|
|
1132 |
if sorted(expected) != sorted(actual_impls):
|
|
1133 |
print 50 * '-'
|
|
1134 |
for impl in sorted(expected): print impl
|
|
1135 |
print 50 * '-'
|
|
1136 |
for impl in sorted(actual_impls): print impl
|
|
1137 |
print 50 * '-'
|
|
1138 |
|
|
1139 |
|
|
1140 |
self.assertEquals(sorted(expected), sorted(actual_impls))
|
|
1141 |
|
|
1142 |
|
|
1143 |
class TestTempFeatureDefinition(unittest.TestCase):
|
|
1144 |
|
|
1145 |
def setUp(self):
|
|
1146 |
plugin.ImplFactory.set_reader_classes_override(MOCK_READER_CLASSES)
|
|
1147 |
|
|
1148 |
def tearDown(self):
|
|
1149 |
plugin.ImplFactory.set_reader_classes_override(None)
|
|
1150 |
|
|
1151 |
def assert_contains_feature(self, config, ref, type, value):
|
|
1152 |
dview = config.get_default_view()
|
|
1153 |
feature = dview.get_feature(ref)
|
|
1154 |
self.assertEquals(type, feature.get_type())
|
|
1155 |
self.assertEquals(value, feature.get_value())
|
|
1156 |
|
|
1157 |
def test_create_feature(self):
|
|
1158 |
config = api.Configuration("test.confml")
|
|
1159 |
def add_feature(setting_ref, value):
|
|
1160 |
config.add_feature(api.Feature(setting_ref), "ExistingFeature")
|
|
1161 |
config.add_data(api.Data(fqr="ExistingFeature." + setting_ref, value=value))
|
|
1162 |
add_feature('String', 'existing value')
|
|
1163 |
add_feature('Boolean', '0')
|
|
1164 |
add_feature('Boolean2', 'true')
|
|
1165 |
|
|
1166 |
Tfd = _plugin_reader.TempVariableDefinition
|
|
1167 |
feadefs = [Tfd('TempFeature.String', 'string', 'testing'),
|
|
1168 |
Tfd('TempFeature.Int', 'int', '500'),
|
|
1169 |
Tfd('TempFeature.Real', 'real', '1.5'),
|
|
1170 |
Tfd('TempFeature.Boolean', 'boolean', 'true'),
|
|
1171 |
Tfd('TempFeature.String2', 'string', 'xyz ${ExistingFeature.String} zyx'),
|
|
1172 |
Tfd('TempFeature.Boolean2', 'boolean', '${ExistingFeature.Boolean}'),
|
|
1173 |
Tfd('TempFeature.Boolean3', 'boolean', '${ExistingFeature.Boolean2}')]
|
|
1174 |
for feadef in feadefs:
|
|
1175 |
feadef.create_feature(config)
|
|
1176 |
|
|
1177 |
# This needs to be done or the default view won't be up-to-date
|
|
1178 |
config.recreate_default_view()
|
|
1179 |
|
|
1180 |
self.assert_contains_feature(config, 'TempFeature.String', 'string', 'testing')
|
|
1181 |
self.assert_contains_feature(config, 'TempFeature.Int', 'int', 500)
|
|
1182 |
self.assert_contains_feature(config, 'TempFeature.Real', 'real', 1.5)
|
|
1183 |
self.assert_contains_feature(config, 'TempFeature.Boolean', 'boolean', True)
|
|
1184 |
self.assert_contains_feature(config, 'TempFeature.String2', 'string', 'xyz existing value zyx')
|
|
1185 |
self.assert_contains_feature(config, 'TempFeature.Boolean2', 'boolean', False)
|
|
1186 |
self.assert_contains_feature(config, 'TempFeature.Boolean3', 'boolean', True)
|
|
1187 |
|
|
1188 |
def test_create_seq_feature(self):
|
|
1189 |
Tsfd = _plugin_reader.TempVariableSequenceDefinition
|
|
1190 |
feadef = Tsfd('TempFeature.Seq', [('String', 'string'),
|
|
1191 |
('Int', 'int'),
|
|
1192 |
('Real', 'real'),
|
|
1193 |
('Boolean', 'boolean'),
|
|
1194 |
('DefaultType', 'string')])
|
|
1195 |
config = api.Configuration("test.confml")
|
|
1196 |
feadef.create_feature(config)
|
|
1197 |
self.assert_contains_feature(config, 'TempFeature.Seq', 'sequence', [])
|
|
1198 |
self.assert_contains_feature(config, 'TempFeature.Seq.String', 'string', [])
|
|
1199 |
self.assert_contains_feature(config, 'TempFeature.Seq.Int', 'int', [])
|
|
1200 |
self.assert_contains_feature(config, 'TempFeature.Seq.Real', 'real', [])
|
|
1201 |
self.assert_contains_feature(config, 'TempFeature.Seq.Boolean', 'boolean', [])
|
|
1202 |
self.assert_contains_feature(config, 'TempFeature.Seq.DefaultType', 'string', [])
|
|
1203 |
|
|
1204 |
fea = config.get_default_view().get_feature('TempFeature.Seq')
|
3
|
1205 |
fea.set_value([['test', 1, 2.0, True, 'foo']])
|
|
1206 |
self.assertEquals(fea.get_value(), [['test', 1, 2.0, True, 'foo']])
|
0
|
1207 |
|
|
1208 |
def _create_mock_impl(self, temp_var_defs):
|
|
1209 |
impl = Mock()
|
|
1210 |
impl.ref = "test.implml"
|
|
1211 |
impl.get_temp_variable_definitions = lambda: temp_var_defs
|
|
1212 |
return impl
|
|
1213 |
|
|
1214 |
def test_create_from_impl_container(self):
|
|
1215 |
impls = plugin.ImplSet()
|
|
1216 |
Tfd = _plugin_reader.TempVariableDefinition
|
|
1217 |
Tsfd = _plugin_reader.TempVariableSequenceDefinition
|
|
1218 |
|
|
1219 |
feadefs = [Tfd('TempFeature.String', 'string', 'testing'),
|
|
1220 |
Tfd('TempFeature.Int', 'int', '500')]
|
|
1221 |
impls.add_implementation(self._create_mock_impl(feadefs))
|
|
1222 |
|
|
1223 |
feadefs = [Tfd('TempFeature.Real', 'real', '1.5'),
|
|
1224 |
Tfd('TempFeature.Boolean', 'boolean', 'true')]
|
|
1225 |
impls.add_implementation(self._create_mock_impl(feadefs))
|
|
1226 |
|
|
1227 |
feadefs = [Tsfd('TempFeature.Seq', [('String', 'string'),
|
|
1228 |
('Int', 'int'),
|
|
1229 |
('Real', 'real'),
|
|
1230 |
('Boolean', 'boolean')])]
|
|
1231 |
impls.add_implementation(self._create_mock_impl(feadefs))
|
|
1232 |
|
|
1233 |
config = api.Configuration("test.confml")
|
|
1234 |
impls.create_temp_features(config)
|
|
1235 |
|
|
1236 |
self.assert_contains_feature(config, 'TempFeature.String', 'string', 'testing')
|
|
1237 |
self.assert_contains_feature(config, 'TempFeature.Int', 'int', 500)
|
|
1238 |
self.assert_contains_feature(config, 'TempFeature.Real', 'real', 1.5)
|
|
1239 |
self.assert_contains_feature(config, 'TempFeature.Boolean', 'boolean', True)
|
|
1240 |
self.assert_contains_feature(config, 'TempFeature.Seq', 'sequence', [])
|
|
1241 |
self.assert_contains_feature(config, 'TempFeature.Seq.String', 'string', [])
|
|
1242 |
self.assert_contains_feature(config, 'TempFeature.Seq.Int', 'int', [])
|
|
1243 |
self.assert_contains_feature(config, 'TempFeature.Seq.Real', 'real', [])
|
|
1244 |
self.assert_contains_feature(config, 'TempFeature.Seq.Boolean', 'boolean', [])
|
|
1245 |
|
|
1246 |
|
|
1247 |
def test_create_from_impl_container_with_duplicates(self):
|
|
1248 |
impls = plugin.ImplSet()
|
|
1249 |
|
|
1250 |
Tfd = _plugin_reader.TempVariableDefinition
|
|
1251 |
feadefs = [Tfd('TempFeature.String', 'string', 'testing'),
|
|
1252 |
Tfd('TempFeature.Int', 'int', '500')]
|
|
1253 |
impls.add_implementation(self._create_mock_impl(feadefs))
|
|
1254 |
|
|
1255 |
feadefs = [Tfd('TempFeature.Real', 'real', '1.5'),
|
|
1256 |
Tfd('TempFeature.Boolean', 'boolean', 'true'),
|
|
1257 |
Tfd('TempFeature.Int', 'int', '500')]
|
|
1258 |
impls.add_implementation(self._create_mock_impl(feadefs))
|
|
1259 |
|
|
1260 |
config = api.Configuration("test.confml")
|
|
1261 |
self.assertRaises(exceptions.AlreadyExists, impls.create_temp_features, config)
|
|
1262 |
|
|
1263 |
def test_create_from_impl_container_with_existing(self):
|
|
1264 |
impls = plugin.ImplSet()
|
|
1265 |
|
|
1266 |
Tfd = _plugin_reader.TempVariableDefinition
|
|
1267 |
feadefs = [Tfd('TempFeature.String', 'string', 'testing'),
|
|
1268 |
Tfd('TempFeature.Int', 'int', '500')]
|
|
1269 |
impls.add_implementation(self._create_mock_impl(feadefs))
|
|
1270 |
|
|
1271 |
feadefs = [Tfd('TempFeature.Real', 'real', '1.5'),
|
|
1272 |
Tfd('TempFeature.Boolean', 'boolean', 'true')]
|
|
1273 |
impls.add_implementation(self._create_mock_impl(feadefs))
|
|
1274 |
|
|
1275 |
config = api.Configuration("test.confml")
|
|
1276 |
config.add_feature(api.Feature("Int"), "TempFeature")
|
3
|
1277 |
#self.assertRaises(exceptions.AlreadyExists, impls.create_temp_features, config)
|
|
1278 |
temp_feature_refs = impls.create_temp_features(config)
|
4
|
1279 |
self.assertEquals(temp_feature_refs.sort(), ['TempFeature.String', 'TempFeature.Real', 'TempFeature.Boolean'].sort())
|
3
|
1280 |
|
0
|
1281 |
|
|
1282 |
class TestCommonImplmlDataReader(unittest.TestCase):
|
|
1283 |
|
|
1284 |
def _read_data(self, xml_data):
|
|
1285 |
etree = utils.etree.fromstring(xml_data)
|
|
1286 |
return _plugin_reader.CommonImplmlDataReader.read_data(etree)
|
|
1287 |
|
|
1288 |
def test_simple_all_tags(self):
|
|
1289 |
XML = """<test xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
1290 |
<phase name="pre"/>
|
|
1291 |
<tag name="target" value="rofs3"/>
|
|
1292 |
<tempVariable ref="Temp.Feature" type="string" value="test"/>
|
|
1293 |
<tempVariableSequence ref="Temp.SeqFeature">
|
|
1294 |
<tempVariable ref="Sub" type="int"/>
|
|
1295 |
</tempVariableSequence>
|
|
1296 |
<settingRefsOverride>
|
|
1297 |
<settingRef value="Foo.Bar"/>
|
|
1298 |
</settingRefsOverride>
|
|
1299 |
<outputRootDir value="output_root"/>
|
|
1300 |
<outputSubDir value="output_sub"/>
|
|
1301 |
</test>"""
|
|
1302 |
actual = self._read_data(XML)
|
|
1303 |
|
|
1304 |
expected = _plugin_reader.CommonImplmlData()
|
|
1305 |
expected.phase = 'pre'
|
|
1306 |
expected.tags = {'target': ['rofs3']}
|
|
1307 |
expected.tempvar_defs = [Tfd('Temp.Feature', 'string', 'test'),
|
|
1308 |
Tsfd('Temp.SeqFeature', [('Sub', 'int')])]
|
|
1309 |
expected.setting_refs_override = Sro(['Foo.Bar'])
|
|
1310 |
expected.output_root_dir = 'output_root'
|
|
1311 |
expected.output_sub_dir = 'output_sub'
|
|
1312 |
|
|
1313 |
self.assertEquals(actual, expected)
|
|
1314 |
|
|
1315 |
def test_invalid_phases(self):
|
|
1316 |
XML = """<test xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
1317 |
<phase/>
|
|
1318 |
</test>"""
|
|
1319 |
self.assertRaises(exceptions.ParseError, self._read_data, XML)
|
|
1320 |
|
|
1321 |
XML = """<test xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
1322 |
<phase name="foo"/>
|
|
1323 |
</test>"""
|
|
1324 |
self.assertRaises(exceptions.ParseError, self._read_data, XML)
|
|
1325 |
|
|
1326 |
def test_valid_phases(self):
|
|
1327 |
def run_test(phase ):
|
|
1328 |
xml_data = """<test xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
1329 |
<phase name="%s"/>
|
|
1330 |
</test>""" % phase
|
|
1331 |
actual = self._read_data(xml_data)
|
|
1332 |
expected = _plugin_reader.CommonImplmlData()
|
|
1333 |
expected.phase = phase
|
|
1334 |
self.assertEquals(actual, expected)
|
|
1335 |
|
|
1336 |
run_test('pre')
|
|
1337 |
run_test('normal')
|
|
1338 |
run_test('post')
|
|
1339 |
|
|
1340 |
def test_invalid_temp_features(self):
|
|
1341 |
def run_test(element_xml_data):
|
|
1342 |
xml_data = """<test xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
1343 |
%s
|
|
1344 |
</test>""" % element_xml_data
|
|
1345 |
self.assertRaises(exceptions.ParseError, self._read_data, xml_data)
|
|
1346 |
|
|
1347 |
run_test('<tempVariable/>')
|
|
1348 |
run_test('<tempVariable ref="Foo.Bar" type="foo"/>')
|
|
1349 |
run_test('<tempVariable ref="Foo.Bar" type="foo" value="x"/>')
|
|
1350 |
|
|
1351 |
run_test('<tempVariableSequence/>')
|
|
1352 |
run_test('<tempVariableSequence ref="Foo.Seq"/>')
|
|
1353 |
run_test('<tempVariableSequence ref="Foo.Seq"><tempVariable/></tempVariableSequence>')
|
|
1354 |
run_test('<tempVariableSequence ref="Foo.Seq"><tempVariable ref="SubFoo" type="foo"/></tempVariableSequence>')
|
|
1355 |
|
|
1356 |
def test_valid_temp_feature_types(self):
|
|
1357 |
def run_test(type):
|
|
1358 |
# Test for simple features
|
|
1359 |
xml_data = """<test xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
1360 |
<tempVariable ref="Foo.Bar" type="%s"/>
|
|
1361 |
</test>""" % type
|
|
1362 |
actual = self._read_data(xml_data)
|
|
1363 |
expected = _plugin_reader.CommonImplmlData()
|
|
1364 |
expected.tempvar_defs = [Tfd('Foo.Bar', type, '')]
|
|
1365 |
self.assertEquals(actual, expected)
|
|
1366 |
|
|
1367 |
# Test for sequence features
|
|
1368 |
xml_data = """<test xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
1369 |
<tempVariableSequence ref="Foo.Bar">
|
|
1370 |
<tempVariable ref="Sub" type="%s"/>
|
|
1371 |
</tempVariableSequence>
|
|
1372 |
</test>""" % type
|
|
1373 |
actual = self._read_data(xml_data)
|
|
1374 |
expected = _plugin_reader.CommonImplmlData()
|
|
1375 |
expected.tempvar_defs = [Tsfd('Foo.Bar', [('Sub', type)])]
|
|
1376 |
self.assertEquals(actual, expected)
|
|
1377 |
|
|
1378 |
run_test('string')
|
|
1379 |
run_test('int')
|
|
1380 |
run_test('real')
|
|
1381 |
run_test('boolean')
|
|
1382 |
|
|
1383 |
def test_setting_refs_override(self):
|
|
1384 |
def check(xml, expected_refs):
|
|
1385 |
xml = '<test xmlns="http://www.symbianfoundation.org/xml/implml/1">%s</test>' % xml
|
|
1386 |
actual = self._read_data(xml)
|
|
1387 |
expected = _plugin_reader.CommonImplmlData()
|
|
1388 |
expected.setting_refs_override = Sro(expected_refs)
|
|
1389 |
self.assertEquals(actual, expected)
|
|
1390 |
|
|
1391 |
check('<settingRefsOverride/>', [])
|
|
1392 |
check('<settingRefsOverride refsIrrelevant="false"/>', [])
|
|
1393 |
check('<settingRefsOverride refsIrrelevant="true"/>', None)
|
|
1394 |
check("""
|
|
1395 |
<settingRefsOverride>
|
|
1396 |
<settingRef value="Foo.Bar"/>
|
|
1397 |
</settingRefsOverride>
|
|
1398 |
""",
|
|
1399 |
['Foo.Bar'])
|
|
1400 |
check("""
|
|
1401 |
<settingRefsOverride>
|
|
1402 |
<settingRef value="Foo.Bar"/>
|
|
1403 |
<settingRef value="Foo.Baz"/>
|
|
1404 |
<settingRef value="Test.Setting"/>
|
|
1405 |
</settingRefsOverride>
|
|
1406 |
""",
|
|
1407 |
['Foo.Bar', 'Foo.Baz', 'Test.Setting'])
|
|
1408 |
|