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