|
1 #============================================================================ |
|
2 #Name : test_fileutils.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 fileutils module. """ |
|
21 |
|
22 import unittest |
|
23 import logging |
|
24 import os |
|
25 import shutil |
|
26 import time |
|
27 import sys |
|
28 import fileutils |
|
29 import archive |
|
30 |
|
31 _logger = logging.getLogger('test.fileutils') |
|
32 |
|
33 |
|
34 _test_file_paths = [ |
|
35 'root_file1.txt', |
|
36 'root_file2.doc', |
|
37 'root_file3_no_extension', |
|
38 |
|
39 'dir1/file1.txt', |
|
40 'dir1/file2.doc', |
|
41 'dir1/file3_no_extension', |
|
42 'dir1/subdir1/subdir1_file.txt', |
|
43 'dir1/subdir2/subdir2_file_no_extension', |
|
44 'dir1/subdir3/', |
|
45 |
|
46 'dir2/', |
|
47 'dir3/subdir/', |
|
48 |
|
49 'wildcard1.txt', |
|
50 'wildcard2.doc', |
|
51 'wildcard3', |
|
52 'wildcard4/', |
|
53 'wildcard5/file.txt', |
|
54 |
|
55 'dir/emptysubdir1/', |
|
56 'dir/emptysubdir2/', |
|
57 'dir/emptysubdir3/', |
|
58 |
|
59 u'test_unicode/test_\u00e9.txt', |
|
60 u'test_unicode/test_\u00e7.txt', |
|
61 u'test_unicode/test_\u00e4.txt', |
|
62 |
|
63 's60/Distribution.Policy.S60', |
|
64 's60/component_public/Distribution.Policy.S60', |
|
65 's60/component_public/component_public_file.txt', |
|
66 's60/component_private/Distribution.Policy.S60', |
|
67 's60/component_private/component_private_file.txt', |
|
68 's60/missing/to_be_removed_9999.txt', |
|
69 's60/missing/subdir/Distribution.Policy.S60', |
|
70 's60/missing/subdir/not_to_be_removed_0.txt', |
|
71 's60/missing/subdir/another_subdir/to_be_removed_9999.txt', |
|
72 's60/UPPERCASE_MISSING/to_be_removed_9999.txt', |
|
73 's60/UPPERCASE_MISSING/subdir/Distribution.Policy.S60', |
|
74 's60/UPPERCASE_MISSING/subdir/not_to_be_removed_0.txt', |
|
75 's60/UPPERCASE_MISSING/subdir/another_subdir/to_be_removed_9999.txt', |
|
76 's60/not_in_cvs/Distribution.Policy.S60', |
|
77 'test_policies/1/Distribution.Policy.S60', |
|
78 'test_policies/2/Distribution.Policy.S60', |
|
79 'test_policies/3/Distribution.Policy.S60', |
|
80 'test_policies/4/Distribution.Policy.S60', |
|
81 'test_policies/5/Distribution.Policy.S60', |
|
82 'test_policies/6/Distribution.Policy.S60', |
|
83 'test_policies/7/Distribution.Policy.S60', |
|
84 'test_policies/8/Distribution.Policy.S60', |
|
85 'test_policies/9/Distribution.Policy.S60', |
|
86 'symbian/distribution.policy', |
|
87 'symbian/dir1/distribution.policy', |
|
88 'symbian/dir2/distribution.policy', |
|
89 'symbian/dir3/distribution.policy', |
|
90 'symbian/dir4/distribution.policy', |
|
91 'symbian/dir5/distribution.policy', |
|
92 's60src/src-a/distribution.policy', |
|
93 's60src/src-b/distribution.policy', |
|
94 's60src/src-c/distribution.policy', |
|
95 |
|
96 'sf/Distribution.Policy.S60', |
|
97 'sf/component_public/Distribution.Policy.S60', |
|
98 'sf/component_public/component_public_file.txt', |
|
99 'sf/component_epl/Distribution.Policy.S60', |
|
100 'sf/component_epl/component_epl_file.txt', |
|
101 'sf/component_sfl/Distribution.Policy.S60', |
|
102 'sf/component_sfl/component_sfl_file.txt', |
|
103 'sf/component_private/Distribution.Policy.S60', |
|
104 'sf/component_private/component_private_file.txt', |
|
105 'sf/missing/to_be_removed_9999.txt', |
|
106 'sf/missing/subdir/Distribution.Policy.S60', |
|
107 'sf/missing/subdir/to_be_removed_9999.txt', |
|
108 'sf/UPPERCASE_MISSING/to_be_removed_9999.txt', |
|
109 'sf/UPPERCASE_MISSING/subdir/Distribution.Policy.S60', |
|
110 'sf/UPPERCASE_MISSING/subdir/to_be_removed_9999.txt', |
|
111 'sf/not_in_cvs/Distribution.Policy.S60', |
|
112 ] |
|
113 |
|
114 _test_file_content = { |
|
115 's60/Distribution.Policy.S60': '0', |
|
116 's60/missing/subdir/Distribution.Policy.S60' : '0', |
|
117 's60/UPPERCASE_MISSING/subdir/Distribution.Policy.S60': '0', |
|
118 's60/component_public/Distribution.Policy.S60': '0', |
|
119 's60/component_private/Distribution.Policy.S60': '1\r\n', |
|
120 'test_policies/1/Distribution.Policy.S60': '\xFF\xFE\x30\x00\x0D\x00\x0D\x00\x0D\x00\x0A\x00', |
|
121 'test_policies/2/Distribution.Policy.S60': '\xEF\xBB\xBF\x30\x0D\x0D\x0A', |
|
122 'test_policies/3/Distribution.Policy.S60': '0 ; %version: 1 %', |
|
123 'test_policies/4/Distribution.Policy.S60': '10 ; %version: 1 %', |
|
124 'test_policies/5/Distribution.Policy.S60': '10ABC10', |
|
125 'test_policies/6/Distribution.Policy.S60': '10ABC10 ; %version: 1 %', |
|
126 'test_policies/7/Distribution.Policy.S60': '08421A2', # good |
|
127 'test_policies/8/Distribution.Policy.S60': '08421A2 ; %version: 1 %', # bad |
|
128 'test_policies/9/Distribution.Policy.S60': '1110A12', # bad |
|
129 's60/not_in_cvs/Distribution.Policy.S60': '77777', |
|
130 'symbian/distribution.policy': 'Category A', |
|
131 'symbian/dir1/distribution.policy': 'Category B', |
|
132 'symbian/dir2/distribution.policy': 'Line one \r\nAnother one \r\nCategory C', |
|
133 'symbian/dir3/distribution.policy': 'Line one \r\nAnother one \r\nAnother one \r\nCategory D', |
|
134 'symbian/dir4/distribution.policy': 'Line one \r\nAnother one \r\nNo Category', |
|
135 'symbian/dir5/distribution.policy': 'Line one \r\nAnother one \r\nagain no category', |
|
136 's60src/src-a/distribution.policy': 'Category A', |
|
137 's60src/src-b/distribution.policy': 'Category B', |
|
138 's60src/src-c/distribution.policy': 'Category C', |
|
139 'sf/Distribution.Policy.S60': '0', |
|
140 'sf/missing/subdir/Distribution.Policy.S60' : '0', |
|
141 'sf/UPPERCASE_MISSING/subdir/Distribution.Policy.S60': '0', |
|
142 'sf/component_public/Distribution.Policy.S60': '0', |
|
143 'sf/component_sfl/Distribution.Policy.S60': '3', |
|
144 'sf/component_epl/Distribution.Policy.S60': '7', |
|
145 'sf/component_private/Distribution.Policy.S60': '1', |
|
146 } |
|
147 |
|
148 """ Used by test_archive. """ |
|
149 root_test_dir = "build/_test_" + str(time.strftime("%H.%M.%S")) |
|
150 |
|
151 def _testpath(subpath): |
|
152 """ Normalised path for test paths. """ |
|
153 return os.path.normpath(os.path.join(root_test_dir, subpath)) |
|
154 |
|
155 def setup_module(): |
|
156 """ Setup files test config. |
|
157 |
|
158 This creates a number of empty files in a temporary directory structure |
|
159 for testing various file selection and archiving operations. |
|
160 """ |
|
161 #print 'setup_module()' |
|
162 #print _test_file_content.keys() |
|
163 for child_path in _test_file_paths: |
|
164 path = os.path.join(root_test_dir, child_path) |
|
165 path_dir = path |
|
166 path_dir = os.path.dirname(path) |
|
167 |
|
168 if (not os.path.exists(path_dir)): |
|
169 _logger.debug('Creating dir: ' + path_dir) |
|
170 os.makedirs(path_dir) |
|
171 |
|
172 if(not path.endswith('/') and not path.endswith('\\')): |
|
173 _logger.debug('Creating file: ' + path) |
|
174 handle = open(path, 'w') |
|
175 # Write any file content that is needed |
|
176 if _test_file_content.has_key(child_path): |
|
177 handle.write(_test_file_content[child_path]) |
|
178 handle.close() |
|
179 |
|
180 def teardown_module(): |
|
181 """ Teardown test config. """ |
|
182 if os.path.exists(root_test_dir): |
|
183 fileutils.rmtree(root_test_dir) |
|
184 |
|
185 |
|
186 class FileScannerTest(unittest.TestCase): |
|
187 """ Test FileScanner class. """ |
|
188 def test_1_scanner_paths(self): |
|
189 """1) String representation of a constructed FileScanner is correct.""" |
|
190 scanner = fileutils.FileScanner(_testpath('test')) |
|
191 scanner.add_include('python/') |
|
192 # new implementation of the scanner doesn't convert modify the pattern strings... |
|
193 expected_result = _testpath('test') + ';include:' + os.path.normpath('python/**') |
|
194 assert str(scanner) == expected_result |
|
195 |
|
196 def test_2_include_1(self): |
|
197 """Files from root are included, no subdirs.""" |
|
198 scanner = fileutils.FileScanner(_testpath('')) |
|
199 scanner.add_include('dir1/*') |
|
200 testpaths = [_testpath('dir1/file1.txt'), |
|
201 _testpath('dir1/file2.doc'), |
|
202 _testpath('dir1/file3_no_extension'), |
|
203 _testpath('dir1/subdir3')] |
|
204 result = [] |
|
205 for path in scanner.scan(): |
|
206 result.append(path) |
|
207 _logger.debug(result) |
|
208 |
|
209 # sorting the resuts |
|
210 testpaths.sort() |
|
211 result.sort() |
|
212 |
|
213 print result |
|
214 print testpaths |
|
215 assert result == testpaths |
|
216 |
|
217 def test_include_single_file(self): |
|
218 """A single file from root is included.""" |
|
219 scanner = fileutils.FileScanner(_testpath('')) |
|
220 scanner.add_include('dir1/file1.txt') |
|
221 testpaths = [_testpath('dir1/file1.txt')] |
|
222 result = [] |
|
223 for path in scanner.scan(): |
|
224 result.append(path) |
|
225 _logger.debug(result) |
|
226 |
|
227 print result |
|
228 print testpaths |
|
229 assert result == testpaths |
|
230 |
|
231 def test_include_single_file_and_glob_path(self): |
|
232 """A single file from root and a glob path are included.""" |
|
233 scanner = fileutils.FileScanner(_testpath('')) |
|
234 scanner.add_include('dir1/file1.txt') |
|
235 scanner.add_include('s60/component_public/') |
|
236 testpaths = [_testpath(u'dir1/file1.txt'), |
|
237 _testpath(u's60/component_public/Distribution.Policy.S60'), |
|
238 _testpath(u's60/component_public/component_public_file.txt'),] |
|
239 result = [] |
|
240 for path in scanner.scan(): |
|
241 result.append(path) |
|
242 |
|
243 if sys.platform == "win32": |
|
244 testpaths = [s.lower() for s in testpaths] |
|
245 result = [s.lower() for s in result] |
|
246 result.sort() |
|
247 testpaths.sort() |
|
248 print result |
|
249 print testpaths |
|
250 assert result == testpaths |
|
251 |
|
252 def test_3_include_2(self): |
|
253 """Files and subdirs are included.""" |
|
254 scanner = fileutils.FileScanner(_testpath('')) |
|
255 scanner.add_include('dir1/**') |
|
256 testpaths = [_testpath('dir1/file1.txt'), |
|
257 _testpath('dir1/file2.doc'), |
|
258 _testpath('dir1/file3_no_extension'), |
|
259 _testpath('dir1/subdir1/subdir1_file.txt'), |
|
260 _testpath('dir1/subdir2/subdir2_file_no_extension'), |
|
261 _testpath('dir1/subdir3')] |
|
262 result = [] |
|
263 for path in scanner.scan(): |
|
264 result.append(path) |
|
265 _logger.debug(result) |
|
266 result.sort() |
|
267 testpaths.sort() |
|
268 print result |
|
269 print testpaths |
|
270 assert result == testpaths |
|
271 |
|
272 def test_4_include_3(self): |
|
273 """Wildcard includes in root.""" |
|
274 scanner = fileutils.FileScanner(_testpath('')) |
|
275 scanner.add_include('wild*') |
|
276 testpaths = [_testpath('wildcard1.txt'), |
|
277 _testpath('wildcard2.doc'), |
|
278 _testpath('wildcard3'), |
|
279 _testpath('wildcard4')] |
|
280 result = [] |
|
281 for path in scanner.scan(): |
|
282 result.append(path) |
|
283 _logger.debug(result) |
|
284 result.sort() |
|
285 testpaths.sort() |
|
286 print result |
|
287 print testpaths |
|
288 assert result == testpaths |
|
289 |
|
290 def test_5_include_4(self): |
|
291 """Include empty dirs.""" |
|
292 scanner = fileutils.FileScanner(_testpath('')) |
|
293 scanner.add_include('dir2/') |
|
294 scanner.add_include('dir3/**') |
|
295 testpaths = [_testpath('dir2'), |
|
296 _testpath('dir3/subdir')] |
|
297 result = [] |
|
298 for path in scanner.scan(): |
|
299 result.append(path) |
|
300 _logger.debug(result) |
|
301 result.sort() |
|
302 testpaths.sort() |
|
303 print result |
|
304 print testpaths |
|
305 assert result == testpaths |
|
306 |
|
307 def test_6_include_exclude_1(self): |
|
308 """Wildcard excludes.""" |
|
309 scanner = fileutils.FileScanner(_testpath('')) |
|
310 scanner.add_include('root*') |
|
311 scanner.add_include('wild*') |
|
312 scanner.add_exclude('root_*') |
|
313 testpaths = [_testpath('wildcard1.txt'), |
|
314 _testpath('wildcard2.doc'), |
|
315 _testpath('wildcard3'), |
|
316 _testpath('wildcard4')] |
|
317 result = [] |
|
318 for path in scanner.scan(): |
|
319 result.append(path) |
|
320 _logger.debug(result) |
|
321 result.sort() |
|
322 testpaths.sort() |
|
323 |
|
324 print result |
|
325 print testpaths |
|
326 assert result == testpaths |
|
327 |
|
328 def test_7_include_exclude_2(self): |
|
329 """Directory can be excluded.""" |
|
330 scanner = fileutils.FileScanner(_testpath('')) |
|
331 scanner.add_include('dir1/') |
|
332 scanner.add_exclude('dir1/subdir1/') |
|
333 scanner.add_exclude('dir1/subdir2/') |
|
334 result = [] |
|
335 [result.append(path) for path in scanner.scan()] |
|
336 testpaths = [_testpath('dir1/file1.txt'), |
|
337 _testpath('dir1/file2.doc'), |
|
338 _testpath('dir1/file3_no_extension'), |
|
339 _testpath('dir1/subdir3')] |
|
340 result.sort() |
|
341 testpaths.sort() |
|
342 |
|
343 print result |
|
344 print testpaths |
|
345 assert result == testpaths |
|
346 |
|
347 def test_8_include_exclude_3(self): |
|
348 """Wildcard exclude.""" |
|
349 scanner = fileutils.FileScanner(_testpath('')) |
|
350 scanner.add_include('dir1/') |
|
351 scanner.add_exclude('**/*.doc') |
|
352 scanner.add_exclude('**/*.txt') |
|
353 result = [] |
|
354 testpaths = [_testpath('dir1/file3_no_extension'), |
|
355 _testpath('dir1/subdir2/subdir2_file_no_extension'), |
|
356 _testpath('dir1/subdir3')] |
|
357 [result.append(path) for path in scanner.scan()] |
|
358 result.sort() |
|
359 testpaths.sort() |
|
360 |
|
361 print result |
|
362 print testpaths |
|
363 assert result == testpaths |
|
364 |
|
365 def test_case_sensitivity(self): |
|
366 """ Test if returned list has correct case. """ |
|
367 scanner = fileutils.FileScanner(_testpath('')) |
|
368 scanner.add_include('s60/UPPERCASE_MISSING/') |
|
369 result = [] |
|
370 testpaths = [_testpath('s60/UPPERCASE_MISSING/to_be_removed_9999.txt'), |
|
371 _testpath('s60/UPPERCASE_MISSING/subdir/Distribution.Policy.S60'), |
|
372 _testpath('s60/UPPERCASE_MISSING/subdir/not_to_be_removed_0.txt'), |
|
373 _testpath('s60/UPPERCASE_MISSING/subdir/another_subdir/to_be_removed_9999.txt') |
|
374 ] |
|
375 [result.append(path) for path in scanner.scan()] |
|
376 |
|
377 testpaths.sort() |
|
378 result.sort() |
|
379 print result |
|
380 print testpaths |
|
381 assert result == testpaths |
|
382 |
|
383 |
|
384 def test_emptydir(self): |
|
385 """Empty dir.""" |
|
386 scanner = fileutils.FileScanner(_testpath('')) |
|
387 scanner.add_include('dir/emptysubdir1/') |
|
388 result = [] |
|
389 testpaths = [_testpath('dir/emptysubdir1')] |
|
390 [result.append(path) for path in scanner.scan()] |
|
391 |
|
392 result.sort() |
|
393 testpaths.sort() |
|
394 |
|
395 print result |
|
396 print testpaths |
|
397 assert result == testpaths |
|
398 |
|
399 def test_emptydirs(self): |
|
400 """Empty dirs.""" |
|
401 scanner = fileutils.FileScanner(_testpath('')) |
|
402 scanner.add_include('dir/') |
|
403 scanner.add_exclude('dir/emptysubdir3/') |
|
404 result = [] |
|
405 testpaths = [_testpath('dir/emptysubdir1'), |
|
406 _testpath('dir/emptysubdir2')] |
|
407 [result.append(path) for path in scanner.scan()] |
|
408 |
|
409 print result |
|
410 print testpaths |
|
411 assert result == testpaths |
|
412 |
|
413 def test_distribution_policy_include(self): |
|
414 """ Distribution policy files can determine file selection - include. """ |
|
415 scanner = fileutils.FileScanner(_testpath('')) |
|
416 scanner.add_include('s60/component_public/') |
|
417 selector = archive.selectors.DistributionPolicySelector(['Distribution.policy.s60'], '0') |
|
418 scanner.add_selector(selector) |
|
419 |
|
420 result = [] |
|
421 [result.append(path) for path in scanner.scan()] |
|
422 testpaths = [_testpath('s60/component_public/component_public_file.txt'), |
|
423 _testpath('s60/component_public/distribution.policy.s60')] |
|
424 |
|
425 result = [s.lower() for s in result] |
|
426 result.sort() |
|
427 testpaths.sort() |
|
428 print result |
|
429 print testpaths |
|
430 assert result == testpaths |
|
431 |
|
432 |
|
433 def test_distribution_policy_exclude(self): |
|
434 """ Distribution policy files can determine file selection - exclude. """ |
|
435 scanner = fileutils.FileScanner(_testpath('')) |
|
436 scanner.add_include('s60/component_private/') |
|
437 selector = archive.selectors.DistributionPolicySelector(['Distribution.policy.s60'], '0') |
|
438 scanner.add_selector(selector) |
|
439 |
|
440 result = [] |
|
441 [result.append(path) for path in scanner.scan()] |
|
442 testpaths = [] |
|
443 |
|
444 assert result == testpaths |
|
445 |
|
446 |
|
447 def test_symbian_distribution_policy_cat_a(self): |
|
448 scanner = fileutils.FileScanner(_testpath('')) |
|
449 scanner.add_include('s60src/src-a/') |
|
450 selector = archive.selectors.SymbianPolicySelector(['distribution.policy'], 'A') |
|
451 scanner.add_selector(selector) |
|
452 |
|
453 result = [] |
|
454 [result.append(path) for path in scanner.scan()] |
|
455 testpaths = [_testpath('s60src/src-a/distribution.policy')] |
|
456 |
|
457 assert result == testpaths |
|
458 |
|
459 def test_symbian_distribution_policy_cat_b(self): |
|
460 scanner = fileutils.FileScanner(_testpath('')) |
|
461 scanner.add_include('s60src/src-b/') |
|
462 selector = archive.selectors.SymbianPolicySelector(['distribution.policy'], 'B') |
|
463 scanner.add_selector(selector) |
|
464 |
|
465 result = [] |
|
466 [result.append(path) for path in scanner.scan()] |
|
467 testpaths = [_testpath('s60src/src-b/distribution.policy')] |
|
468 |
|
469 assert result == testpaths |
|
470 |
|
471 def test_symbian_distribution_policy_cat_not_a_not_b(self): |
|
472 scanner = fileutils.FileScanner(_testpath('')) |
|
473 scanner.add_include('s60src/src-c/') |
|
474 selector = archive.selectors.SymbianPolicySelector(['distribution.policy'], '!A,!B') |
|
475 scanner.add_selector(selector) |
|
476 |
|
477 result = [] |
|
478 [result.append(path) for path in scanner.scan()] |
|
479 |
|
480 testpaths = [_testpath('s60src/src-c/distribution.policy')] |
|
481 |
|
482 assert result == testpaths |
|
483 |
|
484 |
|
485 def test_find_subroots(self): |
|
486 """ Testing the find_subroots method. """ |
|
487 scanner = fileutils.FileScanner(_testpath('')) |
|
488 scanner.add_include('dir/emptysubdir1') |
|
489 scanner.add_include('dir/**/dir') |
|
490 scanner.add_include('foo/**/dir') |
|
491 scanner.add_include('bar/subdir/dir1/**') |
|
492 scanner.add_include('bar/subdir/dir2/**') |
|
493 scanner.add_include('bar/subdir/dir3/x/**') |
|
494 scanner.add_include('bar/subdir/dir3/**') |
|
495 result = scanner.find_subroots() |
|
496 _logger.debug(result) |
|
497 print result |
|
498 assert result == [_testpath('dir'), _testpath('foo'), |
|
499 _testpath('bar/subdir/dir1'), |
|
500 _testpath('bar/subdir/dir2'), |
|
501 _testpath('bar/subdir/dir3')] |
|
502 |
|
503 scanner = fileutils.FileScanner(_testpath('')) |
|
504 scanner.add_include('dir/emptysubdir1') |
|
505 scanner.add_include('**/dir') |
|
506 scanner.add_include('foo/**/dir') |
|
507 result = scanner.find_subroots() |
|
508 _logger.debug(result) |
|
509 assert result == [_testpath('')] |
|
510 |
|
511 |
|
512 def test_load_policy_content(self): |
|
513 try: |
|
514 fileutils.load_policy_content(_testpath('test_policies/1/Distribution.Policy.S60')) |
|
515 assert "Should fail while loading 'test_policies/1/Distribution.Policy.S60'." |
|
516 except: |
|
517 pass |
|
518 |
|
519 try: |
|
520 fileutils.load_policy_content(_testpath('s60/Distribution.Policy.S60')) |
|
521 except: |
|
522 assert "Should not fail while loading 's60/Distribution.Policy.S60'." |
|
523 |
|
524 |
|
525 def assert_policy_file(self, filename, value=None, exception=False): |
|
526 if exception: |
|
527 try: |
|
528 fileutils.read_policy_content(filename) |
|
529 assert "Should fail while loading '%s'." % filename |
|
530 except: |
|
531 pass |
|
532 else: |
|
533 assert fileutils.read_policy_content(filename) == value |
|
534 def assert_symbian_policy_file(self, filename, value=None, exception=False): |
|
535 if exception: |
|
536 try: |
|
537 fileutils.read_symbian_policy_content(filename) |
|
538 assert "Should fail while loading '%s'." % filename |
|
539 except: |
|
540 pass |
|
541 else: |
|
542 assert fileutils.read_symbian_policy_content(filename) == value |
|
543 |
|
544 def test_read_policy_content_strict(self): |
|
545 """ Test policy content using strict rules. """ |
|
546 |
|
547 self.assert_policy_file(_testpath('s60/Distribution.Policy.S60'), value='0') |
|
548 self.assert_policy_file(_testpath('s60/component_private/Distribution.Policy.S60'), value='1') |
|
549 self.assert_policy_file(_testpath('test_policies/1/Distribution.Policy.S60'), exception=True) |
|
550 self.assert_policy_file(_testpath('test_policies/2/Distribution.Policy.S60'), exception=True) |
|
551 self.assert_policy_file(_testpath('test_policies/3/Distribution.Policy.S60'), exception=True) |
|
552 self.assert_policy_file(_testpath('test_policies/4/Distribution.Policy.S60'), exception=True) |
|
553 self.assert_policy_file(_testpath('test_policies/5/Distribution.Policy.S60'), exception=True) |
|
554 self.assert_policy_file(_testpath('test_policies/6/Distribution.Policy.S60'), exception=True) |
|
555 |
|
556 def test_read_policy_content_strict_focalid(self): |
|
557 """ Testing Focal ID support. """ |
|
558 self.assert_policy_file(_testpath('test_policies/7/Distribution.Policy.S60'), value='08421A2') |
|
559 self.assert_policy_file(_testpath('test_policies/8/Distribution.Policy.S60'), exception=True) |
|
560 self.assert_policy_file(_testpath('test_policies/9/Distribution.Policy.S60'), exception=True) |
|
561 |
|
562 def test_read_symbian_policy_content_strict(self): |
|
563 """ Test symbian policy content using strict rules. """ |
|
564 |
|
565 self.assert_symbian_policy_file(_testpath('symbian/distribution.policy'), value='A') |
|
566 self.assert_symbian_policy_file(_testpath('symbian/dir1/distribution.policy'), value='B') |
|
567 self.assert_symbian_policy_file(_testpath('symbian/dir2/distribution.policy'), value='C') |
|
568 self.assert_symbian_policy_file(_testpath('symbian/dir3/distribution.policy'), value='D') |
|
569 self.assert_symbian_policy_file(_testpath('symbian/dir4/distribution.policy'), exception=True) |
|
570 self.assert_symbian_policy_file(_testpath('symbian/dir5/distribution.policy'), exception=True) |
|
571 |
|
572 class TestLongPath(unittest.TestCase): |
|
573 |
|
574 long_path = os.path.join(root_test_dir, '01234567890123456789012345678901234567890123456789', |
|
575 '01234567890123456789012345678901234567890123456789', '01234567890123456789012345678901234567890123456789', |
|
576 '01234567890123456789012345678901234567890123456789', '01234567890123456789012345678901234567890123456789') |
|
577 def setUp(self): |
|
578 self.mkdirs(os.path.join(self.long_path, r'dir1')) |
|
579 self.mkdirs(os.path.join(self.long_path, r'dir2')) |
|
580 if not '\\\\?\\' + os.path.abspath((os.path.join( self.long_path, r'foo.txt'))): |
|
581 import win32file |
|
582 win32file.CreateFileW('\\\\?\\' + os.path.abspath(os.path.join(self.long_path, r'foo.txt')), 0, 0, None, win32file.CREATE_NEW, 0, None) |
|
583 |
|
584 def mkdirs(self, path): |
|
585 if not os.path.isabs(path): |
|
586 path = os.path.join(os.path.abspath('.'), os.path.normpath(path)) |
|
587 if not os.path.exists(os.path.dirname(path)): |
|
588 self.mkdirs(os.path.dirname(path)) |
|
589 self.mkdir(path) |
|
590 |
|
591 def mkdir(self, path): |
|
592 if not os.path.exists(path): |
|
593 if sys.platform == "win32": |
|
594 try: |
|
595 import win32file |
|
596 win32file.CreateDirectoryW('\\\\?\\' + path, None) |
|
597 except: |
|
598 pass |
|
599 else: |
|
600 os.mkdir(path) |
|
601 |
|
602 def test_rmtree_long_path(self): |
|
603 fileutils.rmtree(root_test_dir) |
|
604 assert not os.path.exists(self.long_path) |
|
605 assert not os.path.exists(root_test_dir) |
|
606 |
|
607 def test_rmtree_long_path_unc_format(self): |
|
608 if sys.platform == "win32": |
|
609 fileutils.rmtree(u"\\\\?\\" + os.path.join(os.path.abspath('.'), root_test_dir)) |
|
610 assert not os.path.exists(self.long_path) |
|
611 assert not os.path.exists(root_test_dir) |
|
612 |
|
613 class DestInSrcTest(unittest.TestCase): |
|
614 |
|
615 def test_destinsrc(self): |
|
616 """ Verify that Z:/a/b/c/d is under Z:/a/b/c """ |
|
617 src = r"Z:/a/b/c" |
|
618 dst = r"Z:/a/b/c/d" |
|
619 assert fileutils.destinsrc(src, dst) is True |
|
620 |
|
621 def test_destinsrc2(self): |
|
622 """ Verify that Z:/a/b/c/d is not under Z:/a/b/cc """ |
|
623 src = r"Z:/a/b/cc" |
|
624 dst = r"Z:/a/b/c/d" |
|
625 assert fileutils.destinsrc(src, dst) is False |
|
626 |
|
627 def test_destinsrc_nt(self): |
|
628 """ Verify that Z:/a/b/c/d is under Z:/a/b/C """ |
|
629 src = r"Z:/a/b/C" |
|
630 dst = r"Z:/a/b/c/d" |
|
631 if sys.platform == "win32": |
|
632 assert fileutils.destinsrc(src, dst) is True |
|
633 else: |
|
634 assert fileutils.destinsrc(src, dst) is False |
|
635 |
|
636 def test_destinsrc2_nt(self): |
|
637 """ Verify that Z:/a/b/c/d is not under Z:/a/b/CC """ |
|
638 if sys.platform == "win32": |
|
639 src = r"Z:/a/b/CC" |
|
640 dst = r"Z:/a/b/c/d" |
|
641 assert fileutils.destinsrc(src, dst) is False |