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 pkg_resources
|
|
21 |
try:
|
|
22 |
from cElementTree import ElementTree
|
|
23 |
except ImportError:
|
|
24 |
try:
|
|
25 |
from elementtree import ElementTree
|
|
26 |
except ImportError:
|
|
27 |
try:
|
|
28 |
from xml.etree import cElementTree as ElementTree
|
|
29 |
except ImportError:
|
|
30 |
from xml.etree import ElementTree
|
|
31 |
|
|
32 |
from contentplugin import contentmlparser
|
|
33 |
|
|
34 |
|
|
35 |
invalidxml_string = '<?xml version="1.0" encoding="UTF-8"?><content xmlns="http://www.s60.com/xml/content/1">'
|
|
36 |
|
|
37 |
contentml_string = \
|
|
38 |
'''<?xml version="1.0" encoding="UTF-8"?>
|
|
39 |
<content xmlns="http://www.s60.com/xml/content/1">
|
|
40 |
<tag name='target' value='core'/>
|
|
41 |
<tag name='target' value='rofs3'/>
|
|
42 |
<tag name='test' value='foo'/>
|
|
43 |
<desc>Description field text</desc>
|
|
44 |
<input dir="test">
|
|
45 |
<include pattern="prod"/>
|
|
46 |
<exclude pattern=".svn"/>
|
|
47 |
</input>
|
|
48 |
<output dir="content" someother="sss"/>
|
|
49 |
</content>'''
|
|
50 |
|
|
51 |
contentml_files_string = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
52 |
<content xmlns="http://www.s60.com/xml/content/1">
|
|
53 |
<desc>Description field text</desc>
|
|
54 |
<input dir="test">
|
|
55 |
<include files="test/foobar.txt, test/bar.txt"/>
|
|
56 |
</input>
|
|
57 |
<output dir="content" someother="sss" flatten="true"/>
|
|
58 |
</content>
|
|
59 |
'''
|
|
60 |
|
|
61 |
contentml_string_with_phase = \
|
|
62 |
'<?xml version="1.0" encoding="UTF-8"?>'\
|
|
63 |
'<content xmlns="http://www.s60.com/xml/content/1" phase="pre">'\
|
|
64 |
' <desc>Description field text</desc>'\
|
|
65 |
' <input dir="test">'\
|
|
66 |
' <include pattern="prod"/>'\
|
|
67 |
' <exclude pattern=".svn"/>'\
|
|
68 |
' </input>'\
|
|
69 |
' <output dir="content" someother="sss"/>'\
|
|
70 |
'</content>'
|
|
71 |
|
|
72 |
|
|
73 |
contentml_brief = \
|
|
74 |
'<?xml version="1.0" encoding="UTF-8"?>'\
|
|
75 |
'<content xmlns="http://www.s60.com/xml/content/1">'\
|
|
76 |
' <input dir="test"/>'\
|
|
77 |
' <output dir="content" someother="sss"/>'\
|
|
78 |
'</content>'
|
|
79 |
|
|
80 |
contentml_brief2 = \
|
|
81 |
'<?xml version="1.0" encoding="UTF-8"?>'\
|
|
82 |
'<content xmlns="http://www.s60.com/xml/content/1">'\
|
|
83 |
'</content>'
|
|
84 |
|
|
85 |
|
|
86 |
contentml_with_refs = \
|
|
87 |
'<?xml version="1.0" encoding="UTF-8"?>'\
|
|
88 |
'<content xmlns="http://www.s60.com/xml/content/1">'\
|
|
89 |
' <desc>Description field text</desc>'\
|
|
90 |
' <input dir="${features.inputref}">'\
|
|
91 |
' <include pattern="${features.inputfilter}"/>'\
|
|
92 |
' </input>'\
|
|
93 |
' <output dir="${features.outputref}" someother="sss"/>'\
|
|
94 |
'</content>'
|
|
95 |
|
|
96 |
contentml2_string = \
|
|
97 |
'''<?xml version="1.0" encoding="UTF-8"?>
|
|
98 |
<content xmlns="http://www.s60.com/xml/content/2">
|
|
99 |
<tag name='target' value='core'/>
|
|
100 |
<tag name='target' value='rofs3'/>
|
|
101 |
<tag name='test' value='foo'/>
|
|
102 |
<desc>Description field text</desc>
|
|
103 |
<output dir="content">
|
|
104 |
<input dir="test">
|
|
105 |
<include pattern="prod"/>
|
|
106 |
<exclude pattern=".svn"/>
|
|
107 |
</input>
|
|
108 |
</output>
|
|
109 |
<output dir="${features.outputref}">
|
|
110 |
<input dir="${features.inputref}">
|
|
111 |
<include pattern="${features.inputfilter}"/>
|
|
112 |
</input>
|
|
113 |
</output>
|
|
114 |
</content>'''
|
|
115 |
|
|
116 |
content2_multi = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
117 |
<content xmlns="http://www.s60.com/xml/content/2">
|
|
118 |
<tag name='target' value='foo'/>
|
|
119 |
<output dir="content">
|
|
120 |
<input>
|
|
121 |
<include files="test/override.txt, test/s60.txt"/>
|
|
122 |
</input>
|
|
123 |
</output>
|
|
124 |
<output dir="include" flatten='true'>
|
|
125 |
<input file="test/s60.txt"/>
|
|
126 |
</output>
|
|
127 |
</content>'''
|
|
128 |
|
|
129 |
external_content_multi = '''<?xml version="1.0" encoding="UTF-8"?>
|
|
130 |
<content xmlns="http://www.s60.com/xml/content/2">
|
|
131 |
<desc>Copy only prod</desc>
|
|
132 |
<output dir="content">
|
|
133 |
<externalinput dir="external_content/folder1"/>
|
|
134 |
</output>
|
|
135 |
<output dir="content">
|
|
136 |
<externalinput dir="external_content">
|
|
137 |
<include pattern=".txt"/>
|
|
138 |
<exclude pattern=".svn"/>
|
|
139 |
</externalinput>
|
|
140 |
</output>
|
|
141 |
</content>'''
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
class TestContentParseimpl(unittest.TestCase):
|
|
147 |
|
|
148 |
def test_parse_desc(self):
|
|
149 |
etree = ElementTree.fromstring(contentml_string)
|
|
150 |
reader = contentmlparser.Content1Parser()
|
|
151 |
desc = reader.parse_desc(etree)
|
|
152 |
self.assertEquals(desc,'Description field text')
|
|
153 |
|
|
154 |
def test_parse_output(self):
|
|
155 |
etree = ElementTree.fromstring(contentml_string)
|
|
156 |
reader = contentmlparser.Content1Parser()
|
|
157 |
output = reader.parse_outputs(etree)
|
|
158 |
self.assertEquals(output[0].dir,'content')
|
|
159 |
|
|
160 |
def test_parse_input_dir(self):
|
|
161 |
etree = ElementTree.fromstring(contentml_string)
|
|
162 |
reader = contentmlparser.Content1Parser()
|
|
163 |
input = reader.parse_input(etree)
|
|
164 |
self.assertEquals(input.dir,'test')
|
|
165 |
|
|
166 |
def test_parse_input_include(self):
|
|
167 |
etree = ElementTree.fromstring(contentml_string)
|
|
168 |
reader = contentmlparser.Content1Parser()
|
|
169 |
include = reader.parse_input_include(etree)
|
|
170 |
self.assertEquals(include,{'pattern': ['prod']})
|
|
171 |
|
|
172 |
def test_parse_input_files(self):
|
|
173 |
etree = ElementTree.fromstring(contentml_files_string)
|
|
174 |
reader = contentmlparser.Content1Parser()
|
|
175 |
include = reader.parse_input_include(etree)
|
|
176 |
self.assertEquals(include,{'files': ['test/foobar.txt, test/bar.txt']})
|
|
177 |
|
|
178 |
def test_parse_input_include_not_found(self):
|
|
179 |
etree = ElementTree.fromstring(contentml_brief)
|
|
180 |
reader = contentmlparser.Content1Parser()
|
|
181 |
include = reader.parse_input_include(etree)
|
|
182 |
self.assertEquals(include,{})
|
|
183 |
|
|
184 |
def test_parse_input_exclude(self):
|
|
185 |
etree = ElementTree.fromstring(contentml_string)
|
|
186 |
reader = contentmlparser.Content1Parser()
|
|
187 |
include = reader.parse_input_exclude(etree)
|
|
188 |
self.assertEquals(include,{'pattern': ['.svn']})
|
|
189 |
|
|
190 |
def test_parse_input_exclude_not_found(self):
|
|
191 |
etree = ElementTree.fromstring(contentml_brief)
|
|
192 |
reader = contentmlparser.Content1Parser()
|
|
193 |
include = reader.parse_input_exclude(etree)
|
|
194 |
self.assertEquals(include,{})
|
|
195 |
|
|
196 |
def test_parse_tags(self):
|
|
197 |
etree = ElementTree.fromstring(contentml_string)
|
|
198 |
reader = contentmlparser.Content1Parser()
|
|
199 |
tags = reader.parse_tags(etree)
|
|
200 |
self.assertEquals(tags,{'target' : ['core','rofs3'],
|
|
201 |
'test' : ['foo']})
|
|
202 |
|
|
203 |
class TestContent2Parseimpl(unittest.TestCase):
|
|
204 |
|
|
205 |
def test_parse_desc(self):
|
|
206 |
etree = ElementTree.fromstring(contentml2_string)
|
|
207 |
reader = contentmlparser.Content2Parser()
|
|
208 |
desc = reader.parse_desc(etree)
|
|
209 |
self.assertEquals(desc,'Description field text')
|
|
210 |
|
|
211 |
def test_parse_outputs(self):
|
|
212 |
etree = ElementTree.fromstring(contentml2_string)
|
|
213 |
reader = contentmlparser.Content2Parser()
|
|
214 |
outputs = reader.parse_outputs(etree)
|
|
215 |
self.assertEquals(outputs[0].dir,'content')
|
|
216 |
self.assertEquals(len(outputs[0].inputs),1)
|
|
217 |
self.assertEquals(outputs[0].inputs[0].dir,'test')
|
|
218 |
self.assertEquals(outputs[0].inputs[0].include,{'pattern': ['prod']})
|
|
219 |
self.assertEquals(outputs[1].inputs[0].dir,'${features.inputref}')
|
|
220 |
self.assertEquals(outputs[1].dir,'${features.outputref}')
|
|
221 |
|
|
222 |
|
|
223 |
class TestContentParser(unittest.TestCase):
|
|
224 |
def test_parse_from_string(self):
|
|
225 |
reader = contentmlparser.ContentImplReader()
|
|
226 |
reader.fromstring(contentml_string)
|
|
227 |
self.assertEquals(reader.desc,'Description field text')
|
|
228 |
self.assertEquals(reader.outputs[0].dir,'content')
|
|
229 |
self.assertEquals(reader.outputs[0].inputs[0].dir,'test')
|
|
230 |
self.assertEquals(reader.outputs[0].inputs[0].include, {'pattern':['prod']})
|
|
231 |
self.assertEquals(reader.outputs[0].inputs[0].exclude, {'pattern':['.svn']})
|
|
232 |
self.assertEquals(reader.phase, None)
|
|
233 |
self.assertEquals(reader.tags, {'target' : ['core','rofs3'],
|
|
234 |
'test' : ['foo']})
|
|
235 |
|
|
236 |
def test_parse_from_string_with_phase(self):
|
|
237 |
reader = contentmlparser.ContentImplReader()
|
|
238 |
reader.fromstring(contentml_string_with_phase)
|
|
239 |
self.assertEquals(reader.desc,'Description field text')
|
|
240 |
self.assertEquals(reader.outputs[0].dir,'content')
|
|
241 |
self.assertEquals(reader.outputs[0].inputs[0].dir,'test')
|
|
242 |
self.assertEquals(reader.outputs[0].inputs[0].include, {'pattern':['prod']})
|
|
243 |
self.assertEquals(reader.outputs[0].inputs[0].exclude, {'pattern':['.svn']})
|
|
244 |
self.assertEquals(reader.phase, 'pre')
|
|
245 |
|
|
246 |
def test_parse_from_string_brief(self):
|
|
247 |
reader = contentmlparser.ContentImplReader()
|
|
248 |
reader.fromstring(contentml_brief)
|
|
249 |
self.assertEquals(reader.desc,"")
|
|
250 |
self.assertEquals(reader.outputs[0].dir,'content')
|
|
251 |
self.assertEquals(reader.outputs[0].inputs[0].dir,'test')
|
|
252 |
self.assertEquals(reader.outputs[0].inputs[0].include, {})
|
|
253 |
self.assertEquals(reader.outputs[0].inputs[0].exclude, {})
|
|
254 |
|
|
255 |
def test_parse_from_string_brief2(self):
|
|
256 |
reader = contentmlparser.ContentImplReader()
|
|
257 |
reader.fromstring(contentml_brief2)
|
|
258 |
self.assertEquals(reader.desc,"")
|
|
259 |
self.assertEquals(reader.outputs[0].dir,"")
|
|
260 |
self.assertEquals(len(reader.outputs[0].inputs),0)
|
|
261 |
|
|
262 |
def test_parse_from_string_with_refs(self):
|
|
263 |
reader = contentmlparser.ContentImplReader()
|
|
264 |
reader.fromstring(contentml_with_refs)
|
|
265 |
|
|
266 |
self.assertEquals(reader.outputs[0].dir,"${features.outputref}")
|
|
267 |
self.assertEquals(reader.outputs[0].inputs[0].dir,"${features.inputref}")
|
|
268 |
self.assertEquals(reader.outputs[0].inputs[0].include, {'pattern': ['${features.inputfilter}']} )
|
|
269 |
|
|
270 |
def test_content2_parse_outputs(self):
|
|
271 |
reader = contentmlparser.ContentImplReader()
|
|
272 |
reader.fromstring(contentml2_string)
|
|
273 |
self.assertEquals(reader.outputs[0].dir,'content')
|
|
274 |
self.assertEquals(len(reader.outputs[0].inputs),1)
|
|
275 |
self.assertEquals(reader.outputs[0].inputs[0].dir,'test')
|
|
276 |
self.assertEquals(reader.outputs[0].inputs[0].include,{'pattern': ['prod']})
|
|
277 |
self.assertEquals(reader.outputs[1].inputs[0].dir,'${features.inputref}')
|
|
278 |
self.assertEquals(reader.outputs[1].dir,'${features.outputref}')
|
|
279 |
self.assertEquals(reader.tags, {'target' : ['core','rofs3'],
|
|
280 |
'test' : ['foo']})
|
|
281 |
|
|
282 |
def test_content2_parse_multi(self):
|
|
283 |
reader = contentmlparser.ContentImplReader()
|
|
284 |
reader.fromstring(content2_multi)
|
|
285 |
self.assertEquals(reader.outputs[0].dir,'content')
|
|
286 |
self.assertEquals(len(reader.outputs[0].inputs),1)
|
|
287 |
self.assertEquals(reader.outputs[0].inputs[0].dir,'')
|
|
288 |
self.assertEquals(reader.outputs[0].inputs[0].include,{'files': ['test/override.txt, test/s60.txt']})
|
|
289 |
self.assertEquals(reader.outputs[1].inputs[0].file,'test/s60.txt')
|
|
290 |
self.assertEquals(reader.outputs[1].inputs[0].get_filelist(),['test/s60.txt'])
|
|
291 |
|
|
292 |
def test_external_content_parse_multi(self):
|
|
293 |
reader = contentmlparser.ContentImplReader()
|
|
294 |
reader.fromstring(external_content_multi)
|
|
295 |
self.assertEquals(reader.outputs[0].dir,'content')
|
|
296 |
self.assertEquals(len(reader.outputs[0].inputs),1)
|
|
297 |
self.assertEquals(len(reader.outputs[1].inputs),1)
|
|
298 |
self.assertEquals(reader.outputs[0].inputs[0].dir,'external_content/folder1')
|
|
299 |
self.assertEquals(reader.outputs[0].inputs[0].include,{})
|
|
300 |
self.assertEquals(reader.outputs[1].inputs[0].dir,'external_content')
|
|
301 |
self.assertEquals(reader.outputs[1].inputs[0].include,{'pattern': ['.txt']})
|
|
302 |
|
|
303 |
|
|
304 |
class TestContentOutput(unittest.TestCase):
|
|
305 |
def test_content_output_dir(self):
|
|
306 |
conout = contentmlparser.ContentOutput(dir='foobar/test')
|
|
307 |
self.assertEquals(conout.dir, 'foobar/test')
|
|
308 |
|
|
309 |
def test_content_output_include(self):
|
|
310 |
conout = contentmlparser.ContentOutput(flatten=True)
|
|
311 |
self.assertEquals(conout.flatten, True)
|
|
312 |
|
|
313 |
def test_path_convert(self):
|
|
314 |
conout = contentmlparser.ContentOutput()
|
|
315 |
self.assertEquals(conout.path_convert('z:\\test\\foo\\bar.txt'), 'test\\foo\\bar.txt')
|
|
316 |
self.assertEquals(conout.path_convert('z:/test/foo/bar.txt'), 'test/foo/bar.txt')
|
3
|
317 |
self.assertEquals(conout.path_convert('/test/foo/bar.txt'), 'test/foo/bar.txt')
|
|
318 |
self.assertEquals(conout.path_convert('foo/bar.txt'), 'foo/bar.txt')
|
0
|
319 |
|
5
|
320 |
def test_path_convert_with_sequence_input(self):
|
|
321 |
conout = contentmlparser.ContentOutput()
|
|
322 |
self.assertEquals(conout.path_convert(['z:\\test\\foo\\bar.txt',
|
|
323 |
'z:/test/foo/bar.txt',
|
|
324 |
'/test/foo/bar.txt',
|
|
325 |
'foo/bar.txt']),
|
|
326 |
['test\\foo\\bar.txt',
|
|
327 |
'test/foo/bar.txt',
|
|
328 |
'test/foo/bar.txt',
|
|
329 |
'foo/bar.txt'])
|
|
330 |
|
0
|
331 |
class TestContentInput(unittest.TestCase):
|
|
332 |
def test_content_input_dir(self):
|
|
333 |
conin = contentmlparser.ContentInput(dir='foobar/test')
|
|
334 |
self.assertEquals(conin.dir, 'foobar/test')
|
|
335 |
|
|
336 |
def test_content_include_pattern(self):
|
|
337 |
conin = contentmlparser.ContentInput(include={'pattern':['foo','bar']})
|
|
338 |
self.assertEquals(conin.get_include_pattern(), 'foo')
|
|
339 |
|
|
340 |
def test_content_exclude_pattern(self):
|
|
341 |
conin = contentmlparser.ContentInput(exclude={'pattern':['foo','bar']})
|
|
342 |
self.assertEquals(conin.get_exclude_pattern(), 'foo')
|
|
343 |
|
|
344 |
def test_parse_invalid_xml(self):
|
|
345 |
try:
|
|
346 |
etree = ElementTree.fromstring(invalidxml_string)
|
|
347 |
self.fail('Parsing invalid xml succeeds?')
|
|
348 |
except:
|
|
349 |
pass
|
|
350 |
|
|
351 |
|
|
352 |
if __name__ == '__main__':
|
|
353 |
unittest.main()
|