|
1 #============================================================================ |
|
2 #Name : test_archive.py |
|
3 #Part of : Helium |
|
4 |
|
5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 #All rights reserved. |
|
7 #This component and the accompanying materials are made available |
|
8 #under the terms of the License "Eclipse Public License v1.0" |
|
9 #which accompanies this distribution, and is available |
|
10 #at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 #Initial Contributors: |
|
13 #Nokia Corporation - initial contribution. |
|
14 # |
|
15 #Contributors: |
|
16 # |
|
17 #Description: |
|
18 #=============================================================================== |
|
19 |
|
20 """Test the archive.py module.""" |
|
21 |
|
22 from __future__ import with_statement |
|
23 import os |
|
24 import amara |
|
25 import unittest |
|
26 |
|
27 import archive |
|
28 import configuration |
|
29 import logging |
|
30 import fileutils |
|
31 import xml.dom.minidom |
|
32 import tempfile |
|
33 import test_fileutils |
|
34 |
|
35 _logger = logging.getLogger('test.archive') |
|
36 |
|
37 |
|
38 root_test_dir = test_fileutils.root_test_dir |
|
39 |
|
40 def setup_module(): |
|
41 """ Creates some test data files for file-related testing. """ |
|
42 test_fileutils.setup_module() |
|
43 |
|
44 def teardown_module(): |
|
45 """ Cleans up test data files for file-related testing. """ |
|
46 test_fileutils.teardown_module() |
|
47 |
|
48 |
|
49 class ArchivePreBuilderTest(unittest.TestCase): |
|
50 """Tests that an archive configuration file successfully creates an Ant exec file.""" |
|
51 EXEC_FILE = "archive_create.ant.xml" |
|
52 |
|
53 def test_ant_exec(self): |
|
54 """Tests that an archive configuration file successfully creates an Ant exec file.""" |
|
55 builder = configuration.NestedConfigurationBuilder(os.environ['TEST_DATA'] + '/data/archive_test_input.cfg.xml') |
|
56 archiveConfigSet = builder.getConfiguration() |
|
57 archivePreBuilder = archive.ArchivePreBuilder(archiveConfigSet, "config", index=0) |
|
58 buildFilePath = os.path.join(root_test_dir, r'archive_test.ant.xml') |
|
59 archivePreBuilder.write(buildFilePath) |
|
60 build_file = open(buildFilePath) |
|
61 build_file_content = build_file.read() |
|
62 _logger.debug(build_file_content) |
|
63 resultDoc = amara.parse(build_file_content) |
|
64 build_file.close() |
|
65 # The last target in the Ant file should be called 'all'. Other targets |
|
66 # are named stage1, stage2, etc. |
|
67 self.assert_(resultDoc.project.target[-1].name == 'all') |
|
68 os.remove(buildFilePath) |
|
69 |
|
70 |
|
71 |
|
72 class LogicalArchiveTest(unittest.TestCase): |
|
73 """tests Logical Archive feature""" |
|
74 ## def setup(self): |
|
75 ## """Test setup.""" |
|
76 # builder = configuration.NestedConfigurationBuilder(os.environ['TEST_DATA'] + '/data/archive_test.cfg.xml') |
|
77 # self.archiveConfigSet = builder.getConfiguration() |
|
78 # self.config = self.archiveConfigSet.getConfigurations()[0] |
|
79 # self.archivePreBuilder = archive.ArchivePreBuilder(self.archiveConfigSet) |
|
80 |
|
81 def test_manifest_files(self): |
|
82 """ A LogicalArchive can create a correct manifest. """ |
|
83 configDict = {'root.dir': root_test_dir, |
|
84 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
85 'archives.dir': root_test_dir, |
|
86 'name': 'manifest_test', |
|
87 'include': 'dir1/*.txt', |
|
88 'archive.tool': '7za' |
|
89 } |
|
90 config = configuration.Configuration(configDict) |
|
91 |
|
92 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
93 builder.build_manifest(config) |
|
94 |
|
95 expectedPaths = [os.path.normpath('dir1/file1.txt')] |
|
96 |
|
97 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/manifest_test_includefile.txt') |
|
98 |
|
99 with open(includeFilePath) as f: |
|
100 content = f.readlines() |
|
101 print content |
|
102 print expectedPaths |
|
103 content = [s.strip().lower() for s in content] |
|
104 self.assert_(content == expectedPaths) |
|
105 |
|
106 def test_empty_manifest_file(self): |
|
107 """ A LogicalArchive can handle empty manifest. """ |
|
108 configDict = {'root.dir': root_test_dir, |
|
109 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
110 'archives.dir': root_test_dir, |
|
111 'name': 'manifest_test', |
|
112 'include': 'nothing', |
|
113 'archive.tool': '7za' |
|
114 } |
|
115 config = configuration.Configuration(configDict) |
|
116 |
|
117 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
118 builder.build_manifest(config) |
|
119 |
|
120 expectedPaths = [] |
|
121 |
|
122 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/manifest_test_includefile.txt') |
|
123 |
|
124 with open(includeFilePath) as f: |
|
125 content = f.readlines() |
|
126 print content |
|
127 print expectedPaths |
|
128 content = [s.strip().lower() for s in content] |
|
129 self.assert_(content == expectedPaths) |
|
130 |
|
131 def test_manifest_files_with_exclude_list(self): |
|
132 """ A LogicalArchive can create a correct manifest. """ |
|
133 excludelst = os.path.join(root_test_dir, 'exclude.lst') |
|
134 flh = open(excludelst, 'w+') |
|
135 flh.write("/epoc32/tools/variant/variant.cfg\n") |
|
136 flh.write("\\epoc32\\tools\\abld.pl\n") |
|
137 flh.write(os.path.join(root_test_dir, 'dir1', 'file1.txt') + "\n") |
|
138 flh.write(os.path.join(root_test_dir, 'dir1/subdir1/subdir1_file.txt') + "\n") |
|
139 flh.close() |
|
140 configDict = {'root.dir': root_test_dir, |
|
141 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
142 'archives.dir': root_test_dir, |
|
143 'name': 'manifest_test', |
|
144 'include': 'dir1/**', |
|
145 'exclude.lst': excludelst, |
|
146 'archive.tool': '7za' |
|
147 } |
|
148 config = configuration.Configuration(configDict) |
|
149 |
|
150 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
151 builder.build_manifest(config) |
|
152 |
|
153 expectedPaths = [os.path.normpath('dir1/file2.doc'), |
|
154 os.path.normpath('dir1/file3_no_extension'), |
|
155 os.path.normpath('dir1/subdir2/subdir2_file_no_extension'), |
|
156 os.path.normpath('dir1/subdir3/'), |
|
157 ] |
|
158 expectedPaths.sort() |
|
159 |
|
160 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/manifest_test_includefile.txt') |
|
161 |
|
162 with open(includeFilePath) as f: |
|
163 content = f.readlines() |
|
164 print content |
|
165 print expectedPaths |
|
166 content = [s.strip().lower() for s in content] |
|
167 content.sort() |
|
168 self.assert_(content == expectedPaths) |
|
169 |
|
170 def test_manifest_files_with_exclude_list_abs_nodrive(self): |
|
171 """ A LogicalArchive can create a correct manifest with external list and drive. """ |
|
172 rtd = os.path.splitdrive(os.path.abspath(root_test_dir))[1] |
|
173 excludelst = os.path.join(root_test_dir, 'exclude.lst') |
|
174 flh = open(excludelst, 'w+') |
|
175 flh.write("/epoc32/tools/variant/variant.cfg\n") |
|
176 flh.write("\\epoc32\\tools\\abld.pl\n") |
|
177 flh.write(os.path.join(rtd, 'dir1', 'file1.txt') + "\n") |
|
178 flh.write(os.path.join(rtd, 'dir1/subdir1/subdir1_file.txt') + "\n") |
|
179 flh.close() |
|
180 configDict = {'root.dir': os.path.abspath(root_test_dir), |
|
181 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
182 'archives.dir': root_test_dir, |
|
183 'name': 'manifest_test', |
|
184 'include': 'dir1/**', |
|
185 'exclude.lst': excludelst, |
|
186 'archive.tool': '7za' |
|
187 } |
|
188 config = configuration.Configuration(configDict) |
|
189 |
|
190 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
191 builder.build_manifest(config) |
|
192 |
|
193 expectedPaths = [os.path.normpath('dir1/file2.doc'), |
|
194 os.path.normpath('dir1/file3_no_extension'), |
|
195 os.path.normpath('dir1/subdir2/subdir2_file_no_extension'), |
|
196 os.path.normpath('dir1/subdir3/'), |
|
197 ] |
|
198 expectedPaths.sort() |
|
199 |
|
200 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/manifest_test_includefile.txt') |
|
201 |
|
202 with open(includeFilePath) as f: |
|
203 content = f.readlines() |
|
204 if os.sep == '\\': |
|
205 content = [s.strip().lower() for s in content] |
|
206 else: |
|
207 content = [s.strip() for s in content] |
|
208 content.sort() |
|
209 print content |
|
210 print expectedPaths |
|
211 self.assert_(content == expectedPaths) |
|
212 |
|
213 |
|
214 def test_distribution_policy_config(self): |
|
215 """ tests the distribution policy files configuration""" |
|
216 expected_paths = [os.path.normpath('s60/component_public/component_public_file.txt'), |
|
217 os.path.normpath('s60/component_public/Distribution.Policy.S60'), |
|
218 os.path.normpath('s60/Distribution.Policy.S60'), |
|
219 os.path.normpath('s60/missing/subdir/Distribution.Policy.S60'), |
|
220 os.path.normpath('s60/missing/subdir/not_to_be_removed_0.txt'), |
|
221 os.path.normpath('s60/UPPERCASE_MISSING/subdir/Distribution.Policy.S60'), |
|
222 os.path.normpath('s60/UPPERCASE_MISSING/subdir/not_to_be_removed_0.txt'),] |
|
223 if os.sep == '\\': |
|
224 for i in range(len(expected_paths)): |
|
225 expected_paths[i] = expected_paths[i].lower() |
|
226 self.do_distribution_policy_config(expected_paths, policy='0') |
|
227 |
|
228 expected_paths = [os.path.normpath('s60/component_private/component_private_file.txt'), |
|
229 os.path.normpath('s60/component_private/Distribution.Policy.S60'),] |
|
230 if os.sep == '\\': |
|
231 for i in range(len(expected_paths)): |
|
232 expected_paths[i] = expected_paths[i].lower() |
|
233 self.do_distribution_policy_config(expected_paths, policy='1') |
|
234 |
|
235 expected_paths = [os.path.normpath('s60/missing/subdir/another_subdir/to_be_removed_9999.txt'), |
|
236 os.path.normpath('s60/missing/to_be_removed_9999.txt'), |
|
237 os.path.normpath('s60/UPPERCASE_MISSING/subdir/another_subdir/to_be_removed_9999.txt'), |
|
238 os.path.normpath('s60/UPPERCASE_MISSING/to_be_removed_9999.txt')] |
|
239 if os.sep == '\\': |
|
240 for i in range(len(expected_paths)): |
|
241 expected_paths[i] = expected_paths[i].lower() |
|
242 self.do_distribution_policy_config(expected_paths, policy=archive.mappers.MISSING_POLICY) |
|
243 |
|
244 def do_distribution_policy_config(self, expected_paths, policy): |
|
245 """ . """ |
|
246 configDict = {'root.dir': root_test_dir, |
|
247 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
248 'archives.dir': root_test_dir, |
|
249 'name': 's60_policy_test', |
|
250 'include': 's60/', |
|
251 'distribution.policy.s60': policy, |
|
252 'selectors': 'policy', |
|
253 'archive.tool': '7za' |
|
254 } |
|
255 config = configuration.Configuration(configDict) |
|
256 |
|
257 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
258 builder.build_manifest(config) |
|
259 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/s60_policy_test_includefile.txt') |
|
260 |
|
261 with open(includeFilePath) as f: |
|
262 content = f.readlines() |
|
263 if os.sep == '\\': |
|
264 content = [s.strip().lower() for s in content] |
|
265 else: |
|
266 content = [s.strip() for s in content] |
|
267 content.sort() |
|
268 |
|
269 print content |
|
270 if os.sep == '\\': |
|
271 expected_paths = [s.strip().lower() for s in expected_paths] |
|
272 else: |
|
273 expected_paths = [s.strip() for s in expected_paths] |
|
274 expected_paths.sort() |
|
275 print expected_paths |
|
276 assert content == expected_paths |
|
277 |
|
278 def test_split_manifest_file_unicode(self): |
|
279 """ A LogicalArchive can split a manifest correctly. """ |
|
280 configDict = {'root.dir': os.path.abspath(root_test_dir), |
|
281 'temp.build.dir': os.path.abspath(os.path.join(root_test_dir, 'temp_build_files')), |
|
282 'archives.dir': os.path.abspath(root_test_dir), |
|
283 'name': 'manifest_test_unicode', |
|
284 'max.files.per.archive': '1', |
|
285 'include': 'test_unicode/', |
|
286 'archive.tool': '7za' |
|
287 } |
|
288 config = configuration.Configuration(configDict) |
|
289 |
|
290 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
291 manifest_file_path = builder.build_manifest(config) |
|
292 builder.manifest_to_commands(config, manifest_file_path) |
|
293 |
|
294 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/manifest_test_unicode_includefile.txt') |
|
295 includeFilePath1 = os.path.join(root_test_dir, 'temp_build_files/manifest_test_unicode_part01.txt') |
|
296 includeFilePath2 = os.path.join(root_test_dir, 'temp_build_files/manifest_test_unicode_part02.txt') |
|
297 includeFilePath3 = os.path.join(root_test_dir, 'temp_build_files/manifest_test_unicode_part03.txt') |
|
298 |
|
299 with open(includeFilePath) as f: |
|
300 content = f.readlines() |
|
301 with open(includeFilePath1) as f: |
|
302 content1 = f.readlines() |
|
303 with open(includeFilePath2) as f: |
|
304 content2 = f.readlines() |
|
305 with open(includeFilePath3) as f: |
|
306 content3 = f.readlines() |
|
307 print "content: ", content |
|
308 print "content1: ", content1 |
|
309 print "content2: ", content2 |
|
310 print "content3: ", content2 |
|
311 content = [s.strip() for s in content] |
|
312 self.assert_(len(content) == 3) |
|
313 self.assert_(len(content1) == 1) |
|
314 self.assert_(len(content2) == 1) |
|
315 self.assert_(len(content3) == 1) |
|
316 |
|
317 def test_distribution_policy_mapper_config(self): |
|
318 """ Testing the policy mapper. """ |
|
319 configDict = {'root.dir': root_test_dir, |
|
320 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
321 'archives.dir': root_test_dir, |
|
322 'name': 's60_policy_mapper_test', |
|
323 'include': 's60/', |
|
324 'archive.tool': '7za', |
|
325 'policy.zip2zip': 'true', |
|
326 'mapper': 'policy', |
|
327 'policy.csv': os.path.join(os.environ['TEST_DATA'], 'data/distribution.policy.id_status.csv'), |
|
328 } |
|
329 config = configuration.Configuration(configDict) |
|
330 |
|
331 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
332 manifest_file_path = builder.build_manifest(config) |
|
333 cmds = builder.manifest_to_commands(config, manifest_file_path) |
|
334 |
|
335 |
|
336 expected_paths = ['s60' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
337 's60' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60', |
|
338 's60' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
339 's60' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
340 's60' + os.sep + 'Distribution.Policy.S60', |
|
341 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
342 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
343 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
344 's60' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
345 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
346 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
347 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
348 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
349 's60' + os.sep + 'not_in_cvs' + os.sep + 'Distribution.Policy.S60',] |
|
350 if os.sep == '\\': |
|
351 for i in range(len(expected_paths)): |
|
352 expected_paths[i] = expected_paths[i].lower() |
|
353 expected_paths0 = ['s60' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
354 's60' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
355 's60' + os.sep + 'Distribution.Policy.S60', |
|
356 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
357 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
358 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
359 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt',] |
|
360 if os.sep == '\\': |
|
361 for i in range(len(expected_paths0)): |
|
362 expected_paths0[i] = expected_paths0[i].lower() |
|
363 expected_paths1 = ['s60' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
364 's60' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60'] |
|
365 if os.sep == '\\': |
|
366 for i in range(len(expected_paths1)): |
|
367 expected_paths1[i] = expected_paths1[i].lower() |
|
368 expected_paths9999 = ['s60' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
369 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
370 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
371 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt'] |
|
372 if os.sep == '\\': |
|
373 for i in range(len(expected_paths9999)): |
|
374 expected_paths9999[i] = expected_paths9999[i].lower() |
|
375 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_includefile.txt') |
|
376 includeFilePath0 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_0.txt') |
|
377 includeFilePath1 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_1.txt') |
|
378 includeFilePath9999 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_9999.txt') |
|
379 includeFilePathInternal = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test.internal.txt') |
|
380 |
|
381 content = self.__read_manifest(includeFilePath) |
|
382 expected_paths.sort() |
|
383 print "Content" |
|
384 print content |
|
385 print "Expected" |
|
386 print expected_paths |
|
387 assert content == expected_paths |
|
388 |
|
389 content = self.__read_manifest(includeFilePath0) |
|
390 expected_paths0.sort() |
|
391 print content |
|
392 print expected_paths0 |
|
393 assert content == expected_paths0 |
|
394 |
|
395 content = self.__read_manifest(includeFilePath1) |
|
396 expected_paths1.sort() |
|
397 print content |
|
398 print expected_paths1 |
|
399 assert content == expected_paths1 |
|
400 |
|
401 content = self.__read_manifest(includeFilePath9999) |
|
402 expected_paths9999.sort() |
|
403 print content |
|
404 print expected_paths9999 |
|
405 assert content == expected_paths9999 |
|
406 |
|
407 assert os.path.exists(includeFilePathInternal) == True |
|
408 print "Commands : ", cmds |
|
409 assert len(cmds) == 3 |
|
410 |
|
411 |
|
412 def test_distribution_policy_mapper_config_no_zip2zip(self): |
|
413 """ Testing the policy mapper. """ |
|
414 configDict = {'root.dir': root_test_dir, |
|
415 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
416 'archives.dir': root_test_dir, |
|
417 'name': 's60_policy_mapper_test_noz2z', |
|
418 'include': 's60/', |
|
419 'archive.tool': '7za', |
|
420 'policy.zip2zip': 'false', |
|
421 'mapper': 'policy' |
|
422 } |
|
423 config = configuration.Configuration(configDict) |
|
424 |
|
425 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
426 manifest_file_path = builder.build_manifest(config) |
|
427 cmds = builder.manifest_to_commands(config, manifest_file_path) |
|
428 |
|
429 |
|
430 expected_paths = ['s60' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
431 's60' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60', |
|
432 's60' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
433 's60' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
434 's60' + os.sep + 'Distribution.Policy.S60', |
|
435 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
436 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
437 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
438 's60' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
439 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
440 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
441 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
442 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
443 's60' + os.sep + 'not_in_cvs' + os.sep + 'Distribution.Policy.S60',] |
|
444 if os.sep == '\\': |
|
445 for i in range(len(expected_paths)): |
|
446 expected_paths[i] = expected_paths[i].lower() |
|
447 expected_paths0 = ['s60' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
448 's60' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
449 's60' + os.sep + 'Distribution.Policy.S60', |
|
450 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
451 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
452 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
453 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt',] |
|
454 if os.sep == '\\': |
|
455 for i in range(len(expected_paths0)): |
|
456 expected_paths0[i] = expected_paths0[i].lower() |
|
457 expected_paths1 = ['s60' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
458 's60' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60'] |
|
459 if os.sep == '\\': |
|
460 for i in range(len(expected_paths1)): |
|
461 expected_paths1[i] = expected_paths1[i].lower() |
|
462 expected_paths9999 = ['s60' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
463 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
464 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
465 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt'] |
|
466 if os.sep == '\\': |
|
467 for i in range(len(expected_paths9999)): |
|
468 expected_paths9999[i] = expected_paths9999[i].lower() |
|
469 |
|
470 expected_paths.sort() |
|
471 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_includefile.txt') |
|
472 includeFilePath0 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_0.txt') |
|
473 includeFilePath1 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_1.txt') |
|
474 includeFilePath9999 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_9999.txt') |
|
475 includeFilePathInternal = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_noz2z.internal.txt') |
|
476 |
|
477 content = self.__read_manifest(includeFilePath) |
|
478 expected_paths.sort() |
|
479 print content |
|
480 print expected_paths |
|
481 assert content == expected_paths |
|
482 |
|
483 content = self.__read_manifest(includeFilePath0) |
|
484 expected_paths0.sort() |
|
485 print content |
|
486 print expected_paths0 |
|
487 assert content == expected_paths0 |
|
488 |
|
489 content = self.__read_manifest(includeFilePath1) |
|
490 expected_paths1.sort() |
|
491 print content |
|
492 print expected_paths1 |
|
493 assert content == expected_paths1 |
|
494 |
|
495 content = self.__read_manifest(includeFilePath9999) |
|
496 expected_paths9999.sort() |
|
497 print content |
|
498 print expected_paths9999 |
|
499 assert content == expected_paths9999 |
|
500 |
|
501 assert os.path.exists(includeFilePathInternal) == False |
|
502 print "Commands : ", cmds |
|
503 assert len(cmds) == 1 |
|
504 |
|
505 |
|
506 def test_distribution_policy_mapper_remover_config(self): |
|
507 """ Testing the policy remover mapper. """ |
|
508 configDict = {'root.dir': root_test_dir, |
|
509 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
510 'archives.dir': root_test_dir, |
|
511 'name': 's60_policy_mapper_test', |
|
512 'include': 's60/', |
|
513 'policy.root.dir': os.path.join(root_test_dir, 's60'), |
|
514 'archive.tool': '7za', |
|
515 'mapper': 'policy.remover', |
|
516 'policy.zip2zip': 'true', |
|
517 'policy.csv': os.path.join(os.environ['TEST_DATA'], 'data/distribution.policy.id_status.csv'), |
|
518 } |
|
519 config = configuration.Configuration(configDict) |
|
520 |
|
521 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
522 manifest_file_path = builder.build_manifest(config) |
|
523 cmds = builder.manifest_to_commands(config, manifest_file_path) |
|
524 |
|
525 expected_paths = ['s60' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
526 's60' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60', |
|
527 's60' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
528 's60' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
529 's60' + os.sep + 'Distribution.Policy.S60', |
|
530 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
531 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
532 's60' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
533 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
534 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
535 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
536 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
537 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'another_subdir' + os.sep + 'to_be_removed_9999.txt', |
|
538 's60' + os.sep + 'not_in_cvs' + os.sep + 'Distribution.Policy.S60',] |
|
539 if os.sep == '\\': |
|
540 for i in range(len(expected_paths)): |
|
541 expected_paths[i] = expected_paths[i].lower() |
|
542 expected_paths.sort() |
|
543 expected_paths0 = ['s60' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
544 's60' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
545 's60' + os.sep + 'Distribution.Policy.S60', |
|
546 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
547 's60' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt', |
|
548 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
549 's60' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'not_to_be_removed_0.txt'] |
|
550 if os.sep == '\\': |
|
551 for i in range(len(expected_paths0)): |
|
552 expected_paths0[i] = expected_paths0[i].lower() |
|
553 expected_paths1 = ['s60' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
554 's60' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60'] |
|
555 if os.sep == '\\': |
|
556 for i in range(len(expected_paths1)): |
|
557 expected_paths1[i] = expected_paths1[i].lower() |
|
558 expected_paths1.sort() |
|
559 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_includefile.txt') |
|
560 includeFilePath0 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_0.txt') |
|
561 includeFilePath1 = os.path.join(root_test_dir, 'temp_build_files/s60_policy_mapper_test_1.txt') |
|
562 |
|
563 content = self.__read_manifest(includeFilePath) |
|
564 expected_paths.sort() |
|
565 print content |
|
566 print expected_paths |
|
567 assert content == expected_paths |
|
568 |
|
569 content = self.__read_manifest(includeFilePath0) |
|
570 expected_paths0.sort() |
|
571 print content |
|
572 print expected_paths0 |
|
573 assert content == expected_paths0 |
|
574 |
|
575 content = self.__read_manifest(includeFilePath1) |
|
576 expected_paths1.sort() |
|
577 print content |
|
578 print expected_paths1 |
|
579 assert content == expected_paths1 |
|
580 |
|
581 print cmds |
|
582 assert len(cmds[3]) == 7 |
|
583 |
|
584 |
|
585 def test_distribution_policy_mapper_sf_remover_config(self): |
|
586 """ Testing the policy SFL remover mapper. """ |
|
587 configDict = {'root.dir': root_test_dir, |
|
588 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
589 'archives.dir': root_test_dir, |
|
590 'name': 'sf_policy_sf_mapper_test', |
|
591 'include': 'sf/', |
|
592 'policy.root.dir': os.path.join(root_test_dir, 'sf'), |
|
593 'archive.tool': '7za', |
|
594 'mapper': 'sfl.policy.remover', |
|
595 'policy.zip2zip': 'false', |
|
596 'policy.csv': os.path.join(os.environ['TEST_DATA'], 'data/distribution.policy.extended_for_sf.id_status.csv'), |
|
597 } |
|
598 config = configuration.Configuration(configDict) |
|
599 |
|
600 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
601 manifest_file_path = builder.build_manifest(config) |
|
602 cmds = builder.manifest_to_commands(config, manifest_file_path) |
|
603 |
|
604 expected_paths = ['sf' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
605 'sf' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60', |
|
606 'sf' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
607 'sf' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
608 'sf' + os.sep + 'Distribution.Policy.S60', |
|
609 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
610 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt', |
|
611 'sf' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
612 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nofiles' + os.sep + 'subdir_nofiles2', |
|
613 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nopolicy' + os.sep + 'component_private_file.txt', |
|
614 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
615 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt', |
|
616 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
617 'sf' + os.sep + 'not_in_cvs' + os.sep + 'Distribution.Policy.S60', |
|
618 'sf' + os.sep + 'component_sfl' + os.sep + 'component_sfl_file.txt', |
|
619 'sf' + os.sep + 'component_sfl' + os.sep + 'Distribution.Policy.S60', |
|
620 'sf' + os.sep + 'component_epl' + os.sep + 'component_epl_file.txt', |
|
621 'sf' + os.sep + 'component_epl' + os.sep + 'Distribution.Policy.S60',] |
|
622 if os.sep == '\\': |
|
623 for i in range(len(expected_paths)): |
|
624 expected_paths[i] = expected_paths[i].lower() |
|
625 expected_paths0 = ['sf' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
626 'sf' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
627 'sf' + os.sep + 'Distribution.Policy.S60', |
|
628 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
629 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt', |
|
630 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
631 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt'] |
|
632 if os.sep == '\\': |
|
633 for i in range(len(expected_paths0)): |
|
634 expected_paths0[i] = expected_paths0[i].lower() |
|
635 expected_paths1 = ['sf' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
636 'sf' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60'] |
|
637 if os.sep == '\\': |
|
638 for i in range(len(expected_paths1)): |
|
639 expected_paths1[i] = expected_paths1[i].lower() |
|
640 expected_paths3 = ['sf' + os.sep + 'component_sfl' + os.sep + 'component_sfl_file.txt', |
|
641 'sf' + os.sep + 'component_sfl' + os.sep + 'Distribution.Policy.S60',] |
|
642 if os.sep == '\\': |
|
643 for i in range(len(expected_paths3)): |
|
644 expected_paths3[i] = expected_paths3[i].lower() |
|
645 expected_paths7 = ['sf' + os.sep + 'component_epl' + os.sep + 'component_epl_file.txt', |
|
646 'sf' + os.sep + 'component_epl' + os.sep + 'Distribution.Policy.S60',] |
|
647 if os.sep == '\\': |
|
648 for i in range(len(expected_paths7)): |
|
649 expected_paths7[i] = expected_paths7[i].lower() |
|
650 expected_paths9 = ['sf' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
651 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nofiles' + os.sep + 'subdir_nofiles2', |
|
652 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nopolicy' + os.sep + 'component_private_file.txt', |
|
653 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
654 'sf' + os.sep + 'not_in_cvs' + os.sep + 'Distribution.Policy.S60',] |
|
655 if os.sep == '\\': |
|
656 for i in range(len(expected_paths9)): |
|
657 expected_paths9[i] = expected_paths9[i].lower() |
|
658 |
|
659 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/sf_policy_sf_mapper_test_includefile.txt') |
|
660 includeFilePath0 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_sf_mapper_test_0.txt') |
|
661 includeFilePath1 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_sf_mapper_test_1.txt') |
|
662 includeFilePath3 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_sf_mapper_test_3.txt') |
|
663 includeFilePath7 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_sf_mapper_test_7.txt') |
|
664 includeFilePath9 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_sf_mapper_test_9999.txt') |
|
665 |
|
666 |
|
667 content = self.__read_manifest(includeFilePath) |
|
668 expected_paths.sort() |
|
669 print content |
|
670 print expected_paths |
|
671 assert content == expected_paths |
|
672 |
|
673 content = self.__read_manifest(includeFilePath0) |
|
674 expected_paths0.sort() |
|
675 print content |
|
676 print expected_paths0 |
|
677 assert content == expected_paths0 |
|
678 |
|
679 content = self.__read_manifest(includeFilePath1) |
|
680 expected_paths1.sort() |
|
681 print content |
|
682 print expected_paths1 |
|
683 assert content == expected_paths1 |
|
684 |
|
685 content = self.__read_manifest(includeFilePath3) |
|
686 expected_paths3.sort() |
|
687 print content |
|
688 print expected_paths3 |
|
689 assert content == expected_paths3 |
|
690 |
|
691 content = self.__read_manifest(includeFilePath7) |
|
692 expected_paths7.sort() |
|
693 print content |
|
694 print expected_paths7 |
|
695 assert content == expected_paths7 |
|
696 |
|
697 content = self.__read_manifest(includeFilePath9) |
|
698 expected_paths9.sort() |
|
699 print content |
|
700 print expected_paths9 |
|
701 assert content == expected_paths9 |
|
702 |
|
703 # checking the number of command generated |
|
704 assert len(cmds) == 2, "Must only have 2 steps in the archiving (archiving, removing)." |
|
705 assert len(cmds[0]) == 5, "Must only have 5 output files." |
|
706 print len(cmds[1]) |
|
707 for cmd in cmds[1]: |
|
708 print cmd |
|
709 assert len(cmds[1]) == len(expected_paths)-len(expected_paths3), "Remore must be equal to len(expected_paths) - len(expected_paths3)" |
|
710 |
|
711 def test_distribution_policy_mapper_epl_remover_config(self): |
|
712 """ Testing the policy EPL remover mapper. """ |
|
713 configDict = {'root.dir': root_test_dir, |
|
714 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
715 'archives.dir': root_test_dir, |
|
716 'name': 'sf_policy_epl_mapper_test', |
|
717 'include': 'sf/', |
|
718 'policy.root.dir': os.path.join(root_test_dir, 'sf'), |
|
719 'archive.tool': '7za', |
|
720 'mapper': 'epl.policy.remover', |
|
721 'policy.zip2zip': 'false', |
|
722 'policy.csv': os.path.join(os.environ['TEST_DATA'], 'data/distribution.policy.extended_for_sf.id_status.csv'), |
|
723 } |
|
724 config = configuration.Configuration(configDict) |
|
725 |
|
726 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
727 manifest_file_path = builder.build_manifest(config) |
|
728 cmds = builder.manifest_to_commands(config, manifest_file_path) |
|
729 |
|
730 expected_paths = ['sf' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
731 'sf' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60', |
|
732 'sf' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
733 'sf' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
734 'sf' + os.sep + 'Distribution.Policy.S60', |
|
735 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
736 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt', |
|
737 'sf' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
738 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nofiles' + os.sep + 'subdir_nofiles2', |
|
739 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nopolicy' + os.sep + 'component_private_file.txt', |
|
740 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
741 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt', |
|
742 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
743 'sf' + os.sep + 'not_in_cvs' + os.sep + 'Distribution.Policy.S60', |
|
744 'sf' + os.sep + 'component_sfl' + os.sep + 'component_sfl_file.txt', |
|
745 'sf' + os.sep + 'component_sfl' + os.sep + 'Distribution.Policy.S60', |
|
746 'sf' + os.sep + 'component_epl' + os.sep + 'component_epl_file.txt', |
|
747 'sf' + os.sep + 'component_epl' + os.sep + 'Distribution.Policy.S60',] |
|
748 if os.sep == '\\': |
|
749 for i in range(len(expected_paths)): |
|
750 expected_paths[i] = expected_paths[i].lower() |
|
751 expected_paths0 = ['sf' + os.sep + 'component_public' + os.sep + 'component_public_file.txt', |
|
752 'sf' + os.sep + 'component_public' + os.sep + 'Distribution.Policy.S60', |
|
753 'sf' + os.sep + 'Distribution.Policy.S60', |
|
754 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
755 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt', |
|
756 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'Distribution.Policy.S60', |
|
757 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'subdir' + os.sep + 'to_be_removed_9999.txt',] |
|
758 if os.sep == '\\': |
|
759 for i in range(len(expected_paths0)): |
|
760 expected_paths0[i] = expected_paths0[i].lower() |
|
761 expected_paths1 = ['sf' + os.sep + 'component_private' + os.sep + 'component_private_file.txt', |
|
762 'sf' + os.sep + 'component_private' + os.sep + 'Distribution.Policy.S60',] |
|
763 if os.sep == '\\': |
|
764 for i in range(len(expected_paths1)): |
|
765 expected_paths1[i] = expected_paths1[i].lower() |
|
766 expected_paths3 = ['sf' + os.sep + 'component_sfl' + os.sep + 'component_sfl_file.txt', |
|
767 'sf' + os.sep + 'component_sfl' + os.sep + 'Distribution.Policy.S60',] |
|
768 if os.sep == '\\': |
|
769 for i in range(len(expected_paths3)): |
|
770 expected_paths3[i] = expected_paths3[i].lower() |
|
771 expected_paths7 = ['sf' + os.sep + 'component_epl' + os.sep + 'component_epl_file.txt', |
|
772 'sf' + os.sep + 'component_epl' + os.sep + 'Distribution.Policy.S60',] |
|
773 if os.sep == '\\': |
|
774 for i in range(len(expected_paths7)): |
|
775 expected_paths7[i] = expected_paths7[i].lower() |
|
776 expected_paths9 = ['sf' + os.sep + 'missing' + os.sep + 'to_be_removed_9999.txt', |
|
777 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nofiles' + os.sep + 'subdir_nofiles2', |
|
778 'sf' + os.sep + 'missing' + os.sep + 'subdir' + os.sep + 'subdir_nopolicy' + os.sep + 'component_private_file.txt', |
|
779 'sf' + os.sep + 'UPPERCASE_MISSING' + os.sep + 'to_be_removed_9999.txt', |
|
780 'sf' + os.sep + 'not_in_cvs' + os.sep + 'Distribution.Policy.S60',] |
|
781 if os.sep == '\\': |
|
782 for i in range(len(expected_paths9)): |
|
783 expected_paths9[i] = expected_paths9[i].lower() |
|
784 |
|
785 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/sf_policy_epl_mapper_test_includefile.txt') |
|
786 includeFilePath0 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_epl_mapper_test_0.txt') |
|
787 includeFilePath1 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_epl_mapper_test_1.txt') |
|
788 includeFilePath3 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_epl_mapper_test_3.txt') |
|
789 includeFilePath7 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_epl_mapper_test_7.txt') |
|
790 includeFilePath9 = os.path.join(root_test_dir, 'temp_build_files/sf_policy_epl_mapper_test_9999.txt') |
|
791 |
|
792 |
|
793 content = self.__read_manifest(includeFilePath) |
|
794 expected_paths.sort() |
|
795 print content |
|
796 print expected_paths |
|
797 assert content == expected_paths |
|
798 |
|
799 content = self.__read_manifest(includeFilePath0) |
|
800 expected_paths0.sort() |
|
801 print content |
|
802 print expected_paths0 |
|
803 assert content == expected_paths0 |
|
804 |
|
805 content = self.__read_manifest(includeFilePath1) |
|
806 expected_paths1.sort() |
|
807 print content |
|
808 print expected_paths1 |
|
809 assert content == expected_paths1 |
|
810 |
|
811 content = self.__read_manifest(includeFilePath3) |
|
812 expected_paths3.sort() |
|
813 print content |
|
814 print expected_paths3 |
|
815 assert content == expected_paths3 |
|
816 |
|
817 content = self.__read_manifest(includeFilePath7) |
|
818 expected_paths7.sort() |
|
819 print content |
|
820 print expected_paths7 |
|
821 assert content == expected_paths7 |
|
822 |
|
823 content = self.__read_manifest(includeFilePath9) |
|
824 expected_paths9.sort() |
|
825 print content |
|
826 print expected_paths9 |
|
827 assert content == expected_paths9 |
|
828 |
|
829 # checking the number of command generated |
|
830 assert len(cmds) == 2, "Must only have 2 steps in the archiving (archiving, removing)." |
|
831 assert len(cmds[0]) == 5, "Must only have 5 output files." |
|
832 assert len(cmds[1]) == len(expected_paths)-len(expected_paths3), "Remore must be equal to len(expected_paths) - len(expected_paths3)" |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 def __read_manifest(self, manifest): |
|
838 """ read the file and sort""" |
|
839 with open(manifest) as f: |
|
840 content = f.readlines() |
|
841 if os.sep == '\\': |
|
842 content = [s.strip().lower() for s in content] |
|
843 else: |
|
844 content = [s.strip() for s in content] |
|
845 content.sort() |
|
846 return content |
|
847 |
|
848 |
|
849 def test_split_manifest_file(self): |
|
850 """ A LogicalArchive can split a manifest correctly. """ |
|
851 configDict = {'root.dir': os.path.abspath(root_test_dir), |
|
852 'temp.build.dir': os.path.abspath(os.path.join(root_test_dir, 'temp_build_files')), |
|
853 'archives.dir': os.path.abspath(root_test_dir), |
|
854 'name': 'manifest_test', |
|
855 'max.files.per.archive': '1', |
|
856 'include': 'dir/', |
|
857 'exclude': 'dir/emptysubdir3', |
|
858 'archive.tool': '7za' |
|
859 } |
|
860 config = configuration.Configuration(configDict) |
|
861 |
|
862 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
863 manifest_file_path = builder.build_manifest(config) |
|
864 builder.manifest_to_commands(config, manifest_file_path) |
|
865 |
|
866 expectedPaths = ['dir' + os.sep + 'emptysubdir1','dir' + os.sep + 'emptysubdir2'] |
|
867 expectedPaths1 = ['dir' + os.sep + 'emptysubdir1\n'] |
|
868 expectedPaths2 = ['dir' + os.sep + 'emptysubdir2\n'] |
|
869 |
|
870 includeFilePath = os.path.join(root_test_dir, 'temp_build_files/manifest_test_includefile.txt') |
|
871 includeFilePath1 = os.path.join(root_test_dir, 'temp_build_files/manifest_test_part01.txt') |
|
872 includeFilePath2 = os.path.join(root_test_dir, 'temp_build_files/manifest_test_part02.txt') |
|
873 |
|
874 with open(includeFilePath) as f: |
|
875 content = f.readlines() |
|
876 with open(includeFilePath1) as f: |
|
877 content1 = f.readlines() |
|
878 with open(includeFilePath2) as f: |
|
879 content2 = f.readlines() |
|
880 print "content: ", content |
|
881 print "content1: ", content1 |
|
882 print "content2: ", content2 |
|
883 print "expectedPaths: ", expectedPaths |
|
884 print "expectedPaths1: ", expectedPaths1 |
|
885 print "expectedPaths2: ", expectedPaths2 |
|
886 content = [s.strip().lower() for s in content] |
|
887 self.assert_(content == expectedPaths) |
|
888 self.assert_(content1 == expectedPaths1) |
|
889 self.assert_(content2 == expectedPaths2) |
|
890 |
|
891 class CheckRootDirValueTest(unittest.TestCase): |
|
892 """test root drive value""" |
|
893 def test_checkRootDirValue(self): |
|
894 """ Testing the root drive value. """ |
|
895 configDict = {'root.dir': root_test_dir, |
|
896 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
897 'archives.dir': root_test_dir, |
|
898 'name': 'regular_path_test', |
|
899 'include': 'dir1/*.txt', |
|
900 'archive.tool': '7za' |
|
901 } |
|
902 configDictUnc = {'root.dir': "\\\\server\\share\\dir", |
|
903 'temp.build.dir': os.path.join(root_test_dir, 'temp_build_files'), |
|
904 'archives.dir': root_test_dir, |
|
905 'name': 'unc_test', |
|
906 'include': 'dir1/*.txt', |
|
907 'archive.tool': '7za' |
|
908 } |
|
909 config = configuration.Configuration(configDict) |
|
910 configUnc = configuration.Configuration(configDictUnc) |
|
911 builder = MockedArchivePreBuilder(configuration.ConfigurationSet([config, configUnc]), "config", writerType='make', index=0) |
|
912 builder.rewriteXMLFile(os.path.join(os.environ['TEST_DATA'], 'data/zip_checkDrive_test.cfg.xml'), os.path.join(os.environ['TEST_DATA'], 'data/zip_checkDrive_test.cfg.xml.parsed')) |
|
913 (build_drive, _) = os.path.splitdrive(os.path.normpath(tempfile.gettempdir())) |
|
914 rootList = builder.checkRootDirValue(MockedConfigBuilder(), os.path.join(os.environ['TEST_DATA'], 'data/zip_checkDrive_test.cfg.xml.parsed'), build_drive, 'wvdo_sources') |
|
915 assert rootList is not None |
|
916 if os.sep == '\\': |
|
917 roots = builder.getCommonUncRoots(['\\\\server\\share\\dir', |
|
918 '\\\\server\\share', |
|
919 '\\\\server\\share1\\dir', |
|
920 '\\\\server2\\share\\somedir']) |
|
921 self.assert_(len(roots) == 3) |
|
922 self.assert_('\\\\server\\share\\' in roots) |
|
923 self.assert_('\\\\server\\share1\\' in roots) |
|
924 self.assert_('\\\\server2\\share\\' in roots) |
|
925 |
|
926 class MockedConfigBuilder: |
|
927 """.""" |
|
928 |
|
929 def writeToXML(self, xml_file, configs, parse_xml_file): |
|
930 """writeToXML""" |
|
931 pass |
|
932 |
|
933 |
|
934 class MockedArchivePreBuilder(archive.ArchivePreBuilder): |
|
935 """ .""" |
|
936 def substUncPath(self, _): |
|
937 """ subst the unc path""" |
|
938 if os.sep != '\\': |
|
939 return None |
|
940 return fileutils.get_next_free_drive() |
|
941 |
|
942 def unSubStituteDrives(self, drive): |
|
943 """ unsubstitute the drive""" |
|
944 pass |
|
945 |
|
946 def rewriteXMLFile(self, xml_file, parse_xml_file): |
|
947 """re-write XML file""" |
|
948 doc = xml.dom.minidom.parse(xml_file) |
|
949 out = open(parse_xml_file, 'w') |
|
950 doc.writexml(out, indent='') |
|
951 out.close() |
|
952 |
|
953 |
|
954 class ZipArchiverTest(unittest.TestCase): |
|
955 """ Unit test case for seven zip archiver """ |
|
956 def test_extension(self): |
|
957 t = archive.tools.SevenZipArchiver() |
|
958 self.assert_(t.extension() == ".zip") |
|
959 |
|
960 class SevenZipFormatArchiverTest(unittest.TestCase): |
|
961 """ Testing 7z archiver class """ |
|
962 def test_archive(self): |
|
963 """ Testing whether the ant file for running 7z is created """ |
|
964 configDict = {'root.dir': os.path.abspath(root_test_dir), |
|
965 'temp.build.dir': os.path.abspath(os.path.join(root_test_dir, 'temp_build_files')), |
|
966 'archives.dir': os.path.abspath(root_test_dir), |
|
967 'name': 'manifest_test', |
|
968 'max.files.per.archive': '1', |
|
969 'include': 'dir/', |
|
970 'exclude': 'dir/emptysubdir3', |
|
971 'archive.tool': '7z' |
|
972 } |
|
973 config = configuration.Configuration(configDict) |
|
974 builder = archive.ArchivePreBuilder(configuration.ConfigurationSet([config]), "config", index=0) |
|
975 manifest_file_path = builder.build_manifest(config) |
|
976 builder.manifest_to_commands(config, manifest_file_path) |
|
977 tmpfilename = os.path.join(os.path.abspath(root_test_dir),'test_archive_7z.xml') |
|
978 builder.write(tmpfilename) |
|
979 tmpfileh = open(tmpfilename,'r') |
|
980 content = tmpfileh.read() |
|
981 assert content.find('executable="7z">') != -1 |
|
982 assert content.find('<arg line="a -mx9') != -1 |
|
983 tmpfileh.close() |
|
984 |
|
985 |
|
986 #class ZipArchiverTest(unittest.TestCase): |
|
987 # def setUp(self): |
|
988 # archiveConfig = amara.parse(open(os.environ['TEST_DATA'] + '/data/zip_archive_test.cfg.xml')) |
|
989 # self.archivePreBuilder = archive.ArchivePreBuilder(archiveConfig) |
|
990 # |
|
991 # def testZipArchiverCommand(self): |
|
992 # """Zip archiver creates correct command.""" |
|
993 # archiver = archive.ZipArchiver(self.archivePreBuilder) |
|
994 # archiver._start_archive('foo') |
|
995 # archiver.end_archive() |
|
996 # commands = archiver.commandList.allCommands() |
|
997 # assert len(commands) == 1 |
|
998 # command = commands[0] |
|
999 # assert command.executable() == 'zip.exe' |
|
1000 # assert command.cmd() == '-R . c:\\temp\\foo.zip' |
|
1001 # |
|
1002 # def testZipArchiverOperation(self): |
|
1003 # """Zip archiver runs zip operation correctly.""" |
|
1004 # buildFilePath = self.archivePreBuilder.createArchiveBuildFile('zip_exec.ant.xml') |
|
1005 # result = run(r'ant -f c:\temp\output\temp_build_files\zip_exec.ant.xml all -Dnumber.of.threads=1') |
|
1006 # print result |
|
1007 |
|
1008 def run( command ): |
|
1009 """ run the code""" |
|
1010 #print "Run command: " + command |
|
1011 ( _, stdout ) = os.popen4( command ) |
|
1012 result = stdout.read() |
|
1013 return result |
|
1014 |
|
1015 |
|
1016 if __name__ == "__main__": |
|
1017 unittest.main() |