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