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, shutil
|
|
19 |
import sys
|
|
20 |
import logging
|
|
21 |
import __init__
|
|
22 |
|
|
23 |
from cone.public import exceptions,plugin,api,container
|
|
24 |
from cone.storage import filestorage
|
|
25 |
from contentplugin import contentml
|
|
26 |
|
|
27 |
# Hardcoded value of testdata folder that must be under the current working dir
|
|
28 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
29 |
testdata = os.path.join(ROOT_PATH,'contentproject')
|
|
30 |
|
|
31 |
|
|
32 |
class TestContentPlugin(unittest.TestCase):
|
|
33 |
|
|
34 |
def test_create_copy_list_from_datacontainer_with_test(self):
|
|
35 |
'''
|
|
36 |
Test that the loading of the plugins works
|
|
37 |
'''
|
|
38 |
data = container.DataContainer()
|
|
39 |
data.add_value('test/test.txt','/foo/content/test/test.txt')
|
|
40 |
data.add_value('test/test.txt','/bar/content/test/test.txt')
|
|
41 |
data.add_value('product/aaa.txt','/foo/content/product/aaa.txt')
|
|
42 |
data.add_value('images/kuva.jpg','/foo/content/images/kuva.jpg')
|
|
43 |
data.add_value('include/hide.iby','/bar/content/include/hide.iby')
|
|
44 |
impl = contentml.ContentImpl("foo",None)
|
|
45 |
copylist = impl.create_copy_list(content=data, input='test',output='content')
|
|
46 |
self.assertEquals(copylist[0][1],'content/test.txt')
|
|
47 |
|
|
48 |
def test_create_copy_list_from_datacontainer_with_defauls(self):
|
|
49 |
'''
|
|
50 |
Test that the loading of the plugins works
|
|
51 |
'''
|
|
52 |
data = container.DataContainer()
|
|
53 |
data.add_value('test/test.txt','/foo/content/test/test.txt')
|
|
54 |
data.add_value('test/test.txt','/bar/content/test/test.txt')
|
|
55 |
data.add_value('product/aaa.txt','/foo/content/product/aaa.txt')
|
|
56 |
data.add_value('images/kuva.jpg','/foo/content/images/kuva.jpg')
|
|
57 |
data.add_value('include/hide.iby','/bar/content/include/hide.iby')
|
|
58 |
impl = contentml.ContentImpl("foo",None)
|
|
59 |
copylist = impl.create_copy_list(content=data)
|
|
60 |
self.assertEquals(copylist[0][0],'/bar/content/test/test.txt')
|
|
61 |
self.assertEquals(copylist[0][1],'test/test.txt')
|
|
62 |
self.assertEquals(copylist[1][0],'/bar/content/include/hide.iby')
|
|
63 |
self.assertEquals(copylist[1][1],'include/hide.iby')
|
|
64 |
|
|
65 |
def test_create_copy_list_from_datacontainer_with_filters(self):
|
|
66 |
'''
|
|
67 |
Test that the loading of the plugins works
|
|
68 |
'''
|
|
69 |
data = container.DataContainer()
|
|
70 |
data.add_value('test/test.txt','/foo/content/test/test.txt')
|
|
71 |
data.add_value('test/test.txt','/bar/content/test/test.txt')
|
|
72 |
data.add_value('product/aaa.txt','/foo/content/product/aaa.txt')
|
|
73 |
data.add_value('images/kuva.jpg','/foo/content/images/kuva.jpg')
|
|
74 |
data.add_value('include/hide.iby','/bar/content/include/hide.iby')
|
|
75 |
impl = contentml.ContentImpl("foo",None)
|
|
76 |
copylist = impl.create_copy_list(content=data,input='include',include_filter='*.iby')
|
|
77 |
self.assertEquals(copylist[0][0],'/bar/content/include/hide.iby')
|
|
78 |
self.assertEquals(copylist[0][1],'hide.iby')
|
|
79 |
|
|
80 |
class TestContentPluginOnFileStorage(unittest.TestCase):
|
|
81 |
def setUp(self):
|
|
82 |
self.curdir = os.getcwd()
|
|
83 |
self.output = 'output'
|
|
84 |
self.workdir = 'workdir'
|
|
85 |
if not os.path.exists(self.workdir):
|
|
86 |
os.mkdir(self.workdir)
|
|
87 |
os.chdir(self.workdir)
|
|
88 |
pass
|
|
89 |
|
|
90 |
def tearDown(self):
|
|
91 |
os.chdir(self.curdir)
|
|
92 |
if os.path.exists(self.workdir):
|
|
93 |
shutil.rmtree(self.workdir)
|
|
94 |
pass
|
|
95 |
|
|
96 |
def load_config(self, config='product.confml'):
|
|
97 |
fs = filestorage.FileStorage(testdata)
|
|
98 |
p = api.Project(fs)
|
|
99 |
return p.get_configuration(config)
|
|
100 |
|
|
101 |
def load_impl(self, resource_ref, config='product.confml'):
|
|
102 |
configuration = self.load_config(config)
|
|
103 |
impls = plugin.ImplFactory.get_impls_from_file(resource_ref, configuration)
|
|
104 |
self.assertEquals(len(impls), 1)
|
|
105 |
impl = impls[0]
|
|
106 |
impl.set_output_root(self.output)
|
|
107 |
return impl
|
|
108 |
|
|
109 |
def test_configuration_parse_resource(self):
|
|
110 |
impl = self.load_impl('assets/s60/implml/test_filter_both.content')
|
|
111 |
self.assertEquals(impl.outputs[0].dir,'content')
|
|
112 |
self.assertEquals(impl.outputs[0].inputs[0].include,{'pattern': ['prod']})
|
|
113 |
self.assertEquals(impl.outputs[0].inputs[0].exclude,{'pattern': ['.svn']})
|
|
114 |
self.assertEquals(impl.get_tags(), {'target': ['rofs3', 'uda']})
|
|
115 |
self.assertEquals(impl.has_tag({'target':['rofs3']}), True)
|
|
116 |
|
|
117 |
|
|
118 |
def test_configuration_parse_content2(self):
|
|
119 |
impl = self.load_impl('assets/s60/implml/content2_with_tags.content')
|
|
120 |
self.assertEquals(impl.outputs[0].dir,'content')
|
|
121 |
self.assertEquals(impl.outputs[0].inputs[0].include,{'files': ['test/override.txt, test/s60.txt']})
|
|
122 |
self.assertEquals(impl.get_tags(), {'target': ['rofs3', 'uda']})
|
|
123 |
self.assertEquals(impl.has_tag({'target':['rofs3']}), True)
|
|
124 |
|
|
125 |
def test_configuration_parse_content2_with_tag_refs(self):
|
|
126 |
impl = self.load_impl('assets/s60/implml/content2_with_tags_refs.content')
|
|
127 |
self.assertEquals(impl.get_tags(), {'target': ['rofs3']})
|
|
128 |
self.assertEquals(impl.has_tag({'target':['rofs3']}), True)
|
|
129 |
|
|
130 |
def test_configuration_parse_and_filter_implementation_with_tags(self):
|
|
131 |
fs = filestorage.FileStorage(testdata)
|
|
132 |
p = api.Project(fs)
|
|
133 |
config = p.get_configuration('product.confml')
|
|
134 |
impls = plugin.get_impl_set(config,'\.content$')
|
|
135 |
impls_rofs3 = impls.filter_implementations(tags={'target':['rofs3']})
|
|
136 |
self.assertEquals(len(list(impls_rofs3)),3)
|
|
137 |
|
|
138 |
def test_configuration_parse_content_with_include_files(self):
|
|
139 |
impl = self.load_impl('assets/s60/implml/copy_files.content')
|
|
140 |
self.assertEquals(impl.outputs[0].inputs[0].include['files'],['test/override.txt, test/s60.txt'])
|
|
141 |
|
|
142 |
def test_configuration_content_get_full_copy_list(self):
|
|
143 |
impl = self.load_impl('assets/s60/implml/copy_files.content')
|
|
144 |
files = impl.get_full_copy_list()
|
|
145 |
self.assertEquals(files[0],('family/content/test/override.txt', 'output/content/test/override.txt', False))
|
|
146 |
|
|
147 |
def test_configuration_content_list_output_files(self):
|
|
148 |
config = self.load_config()
|
|
149 |
impls = plugin.get_impl_set(config,'\.content$')
|
|
150 |
impls.output = self.output
|
|
151 |
files = impls.list_output_files()
|
|
152 |
self.assertTrue('output/content/test/override.txt' in files)
|
|
153 |
|
|
154 |
def test_configuration_content_list_output_files_with_refs_filter(self):
|
|
155 |
impl = self.load_impl('assets/s60/implml/test_content_with_sequence_refs.content')
|
|
156 |
files = impl.list_output_files()
|
|
157 |
self.assertEquals(files[0],'output/content/override.txt')
|
|
158 |
|
|
159 |
def test_configuration_content_list_output_files_with_exclude_filter(self):
|
|
160 |
impl = self.load_impl('assets/s60/implml/test_filter_both.content')
|
|
161 |
files = impl.list_output_files()
|
|
162 |
self.assertEquals(files[0],'output/content/prodX/jee/ProdX_specific.txt')
|
|
163 |
#
|
|
164 |
def test_configuration_get_input_with_ref(self):
|
|
165 |
impl = self.load_impl('assets/s60/implml/test_content_with_refs.content')
|
|
166 |
self.assertEquals(impl.outputs[0].dir, 'content')
|
|
167 |
self.assertEquals(impl.outputs[0].inputs[0].dir, 'content')
|
|
168 |
|
|
169 |
def test_configuration_get_include_with_refs(self):
|
|
170 |
impl = self.load_impl('assets/s60/implml/test_content_with_sequence_refs.content')
|
|
171 |
self.assertEquals(impl.outputs[0].inputs[0].include['files'], ['test/override.txt'])
|
|
172 |
self.assertEquals(impl.list_output_files(), ['output/content/override.txt'])
|
|
173 |
|
|
174 |
def test_configuration_get_include_with_refs(self):
|
|
175 |
impl = self.load_impl('assets/s60/implml/copy.content')
|
|
176 |
expected = ['output/content/prodX/jee/ProdX_specific.txt',
|
|
177 |
'output/content/test/shout.txt',
|
|
178 |
'output/content/test/override.txt',
|
|
179 |
'output/content/test/s60.txt',
|
|
180 |
'output/content/test/test_CAP_letters.txt']
|
|
181 |
actual = impl.list_output_files()
|
|
182 |
self.assertEquals(sorted(actual), sorted(expected))
|
|
183 |
|
|
184 |
def test_configuration_content_create_output(self):
|
|
185 |
impl = self.load_impl('assets/s60/implml/copy.content')
|
|
186 |
impl.set_output_root(self.output)
|
|
187 |
impl.logger.setLevel(logging.DEBUG)
|
|
188 |
impl.create_output()
|
|
189 |
self.assertTrue(os.path.exists(impl.output))
|
|
190 |
self.assertTrue(os.path.exists(os.path.join(impl.output,'content/prodX/jee/ProdX_specific.txt')))
|
|
191 |
|
|
192 |
def test_configuration_content_generate(self):
|
|
193 |
config = self.load_config()
|
|
194 |
impls = plugin.get_impl_set(config,'\.content$')
|
|
195 |
impls.output = self.output
|
|
196 |
results = impls.generate()
|
|
197 |
self.assertTrue(os.path.exists(impls.output))
|
|
198 |
self.assertTrue(os.path.exists(os.path.join(impls.output,'content/prodX/jee/ProdX_specific.txt')))
|
|
199 |
|
|
200 |
def test_configuration_content_generate_with_include_refs(self):
|
|
201 |
impl = self.load_impl('assets/s60/implml/test_content_with_sequence_refs.content')
|
|
202 |
impl.set_output_root(self.output)
|
|
203 |
results = impl.generate()
|
|
204 |
self.assertTrue(os.path.exists(impl.output))
|
|
205 |
self.assertTrue(os.path.exists(os.path.join(impl.output,'content/override.txt')))
|
|
206 |
|
|
207 |
def test_configuration_content_generate_with_multi_output(self):
|
|
208 |
impl = self.load_impl('assets/s60/implml/content2_with_multi_outputs.content')
|
|
209 |
impl.set_output_root(self.output)
|
|
210 |
results = impl.generate()
|
|
211 |
self.assertTrue(os.path.exists(impl.output))
|
|
212 |
self.assertTrue(os.path.exists(os.path.join(impl.output,'content/test/override.txt')))
|
|
213 |
self.assertTrue(os.path.exists(os.path.join(impl.output,'include/s60.txt')))
|
|
214 |
|
|
215 |
def test_configuration_content_generate_with_refs(self):
|
|
216 |
impl = self.load_impl('assets/s60/implml/test_content_with_refs2.content')
|
|
217 |
impl.set_output_root(self.output)
|
|
218 |
results = impl.generate()
|
|
219 |
self.assertTrue(os.path.exists(impl.output))
|
|
220 |
self.assertTrue(os.path.exists(os.path.join(impl.output,'content2p1/content2p2/override.txt')))
|
|
221 |
|
|
222 |
def test_configuration_content_generate_with_refs2(self):
|
|
223 |
impl = self.load_impl('assets/s60/implml/test_content_with_refs3.content')
|
|
224 |
impl.set_output_root(self.output)
|
|
225 |
results = impl.generate()
|
|
226 |
self.assertTrue(os.path.exists(impl.output))
|
|
227 |
self.assertTrue(os.path.exists(os.path.join(impl.output,'example/content2p2/override.txt')))
|
|
228 |
|
|
229 |
def test_configuration_content_generate_capital_letters(self):
|
|
230 |
impl = self.load_impl('assets/s60/implml/test_content_capital_file_input.content')
|
|
231 |
impl.set_output_root(self.output)
|
|
232 |
results = impl.generate()
|
|
233 |
self.assertTrue(os.path.exists(impl.output))
|
|
234 |
self.assertTrue(os.path.exists(os.path.join(impl.output,'content/test_CAP_letters.txt')))
|
|
235 |
|
|
236 |
def test_get_refs(self):
|
|
237 |
def check(filename, expected_refs):
|
|
238 |
impl = self.load_impl('assets/s60/implml/' + filename)
|
|
239 |
actual_refs = impl.get_refs()
|
|
240 |
|
|
241 |
if expected_refs is None:
|
|
242 |
self.assertEquals(actual_refs, None)
|
|
243 |
else:
|
|
244 |
self.assertTrue(actual_refs is not None)
|
|
245 |
self.assertEquals(sorted(actual_refs), sorted(expected_refs))
|
|
246 |
|
|
247 |
check('content2_with_multi_outputs.content', None)
|
|
248 |
check('content2_with_tags_refs.content', None)
|
|
249 |
check('content2_with_tags.content', None)
|
|
250 |
check('copy_files.content', None)
|
|
251 |
check('copy.content', None)
|
|
252 |
check('test_content_with_refs.content', ['content.inputdir'])
|
|
253 |
check('test_content_with_refs2.content', ['content.inputdir2'])
|
|
254 |
check('test_content_with_refs3.content', ['content.inputdir2'])
|
|
255 |
check('test_content_with_sequence_refs.content', ['ContentFiles.contentfile.fileelem.localPath'])
|
|
256 |
check('test_external_input.content', None)
|
|
257 |
check('test_external_with_ref.content', ['CTD_Special.InputPath'])
|
|
258 |
check('test_filter_both.content', None)
|
|
259 |
|
|
260 |
if __name__ == '__main__':
|
|
261 |
unittest.main()
|