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