|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 import os, unittest, zipfile |
|
18 from testautomation import zip_dir |
|
19 |
|
20 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
21 test_data_dir = os.path.join(ROOT_PATH, 'testdata/zip_dir/test') |
|
22 temp_dir = os.path.join(ROOT_PATH, 'temp/zip_dir') |
|
23 |
|
24 class TestZipDir(unittest.TestCase): |
|
25 def test_zip_dir(self): |
|
26 zip_file = os.path.join(temp_dir, 'test.zip') |
|
27 if os.path.exists(zip_file): |
|
28 os.remove(zip_file) |
|
29 |
|
30 zip_dir.zip_dir(test_data_dir, zip_file, [zip_dir.SVN_IGNORE_PATTERN, r'^ignored.txt$']) |
|
31 |
|
32 self.assertTrue(os.path.isfile(zip_file)) |
|
33 |
|
34 zf = zipfile.ZipFile(zip_file, 'r') |
|
35 namelist = zf.namelist() |
|
36 zf.close() |
|
37 |
|
38 expected = [ |
|
39 'test.txt', |
|
40 'subdir1/test.txt', |
|
41 'subdir1/empty_dir/', |
|
42 'subdir1/subsubdir/test.txt', |
|
43 'subdir2/empty_dir/', |
|
44 ] |
|
45 self.assertEquals(sorted(expected), sorted(namelist)) |