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