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