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