587
|
1 |
#============================================================================
|
|
2 |
#Name : test_deltazip.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 |
#===============================================================================
|
588
|
19 |
""" test delta zip"""
|
587
|
20 |
|
|
21 |
from __future__ import with_statement
|
|
22 |
import unittest
|
|
23 |
import delta_zip
|
|
24 |
import logging
|
|
25 |
import os
|
|
26 |
import sys
|
|
27 |
import tempfile
|
|
28 |
|
|
29 |
class DeltaZipTest( unittest.TestCase ):
|
|
30 |
""" Unit tests for the delta zip tool. """
|
|
31 |
def setUp(self):
|
588
|
32 |
"""setUp automatically called before running the tests"""
|
587
|
33 |
self.cwd_backup = os.getcwd()
|
|
34 |
self.logger = logging.getLogger('test.deltazip')
|
|
35 |
self.root = os.environ['TEST_DATA']
|
628
|
36 |
self.output = tempfile.mkdtemp()
|
|
37 |
self.output2 = tempfile.mkdtemp()
|
587
|
38 |
|
|
39 |
logging.basicConfig(level=logging.INFO)
|
|
40 |
|
|
41 |
def test_MD5SignatureBuilder(self):
|
588
|
42 |
"""test MD5 signature Builder"""
|
587
|
43 |
output = os.path.join(self.output2, 'md5_list.txt')
|
588
|
44 |
_ = os.path.join(self.output2, 'delta.md5')
|
587
|
45 |
|
|
46 |
if os.path.exists(output):
|
|
47 |
os.remove(output)
|
|
48 |
|
|
49 |
sig = delta_zip.MD5SignatureBuilderEBS(self.root, 1, self.output2, '', output)
|
|
50 |
sig.write_build_file()
|
|
51 |
if sys.platform == 'win32':
|
|
52 |
assert os.path.splitdrive(self.root)[0] + os.sep not in open(output).read()
|
|
53 |
assert os.path.exists(output)
|
588
|
54 |
|
587
|
55 |
def test_DeltaZipBuilder(self):
|
588
|
56 |
"""test delta Zip Builder"""
|
587
|
57 |
if not os.path.exists(self.output):
|
|
58 |
os.mkdir(self.output)
|
|
59 |
|
|
60 |
md5output = os.path.join(self.output, 'delta.md5')
|
|
61 |
oldmd5output = os.path.join(self.output, 'olddelta.md5')
|
|
62 |
|
|
63 |
thisfile = os.path.abspath(__file__)
|
|
64 |
md5string = """
|
|
65 |
Host:fasym014
|
|
66 |
Username:ssteiner
|
|
67 |
Date-Time:Fri Aug 17 08:47:40 2007
|
|
68 |
Version:0.02
|
|
69 |
Directory:z:\
|
|
70 |
FileList:z:\output/delta_zip\list_files.txt
|
|
71 |
Exclusion(s):
|
|
72 |
Inclusion(s):
|
|
73 |
----------------
|
|
74 |
%s TYPE=unknown format MD5=34dcda0d351c75e4942b55e1b2e2422f
|
|
75 |
""" % thisfile
|
|
76 |
|
|
77 |
|
|
78 |
tempoutput = open(md5output, 'w')
|
|
79 |
tempoutput.write(md5string)
|
|
80 |
tempoutput.close()
|
|
81 |
|
|
82 |
md5string = """
|
|
83 |
Host:fasym014
|
|
84 |
Username:ssteiner
|
|
85 |
Date-Time:Fri Aug 17 08:47:40 2007
|
|
86 |
Version:0.02
|
|
87 |
Directory:z:\
|
|
88 |
FileList:z:\output/delta_zip\list_files.txt
|
|
89 |
Exclusion(s):
|
|
90 |
Inclusion(s):
|
|
91 |
----------------
|
|
92 |
%s TYPE=unknown format MD5=34dcda0d351c75e4942b55e1b2e2422g
|
|
93 |
""" % thisfile
|
|
94 |
|
|
95 |
tempoutput = open(oldmd5output, 'w')
|
|
96 |
tempoutput.write(md5string)
|
|
97 |
tempoutput.close()
|
|
98 |
|
|
99 |
deltazipfile = os.path.join(self.output, 'delta.zip')
|
|
100 |
deltaantfile = os.path.join(self.output, 'delta.ant.xml')
|
|
101 |
deletefile = os.path.join(self.output, 'delta_zip_specialInstructions.xml')
|
|
102 |
|
|
103 |
|
|
104 |
delta = delta_zip.DeltaZipBuilder(self.root, self.output, oldmd5output, md5output)
|
|
105 |
delta.create_delta_zip(deltazipfile, deletefile, 1, deltaantfile)
|
|
106 |
|
|
107 |
def test_changedFiles(self):
|
588
|
108 |
"""test changed Files"""
|
587
|
109 |
dir1 = tempfile.mkdtemp()
|
|
110 |
dir2 = tempfile.mkdtemp()
|
|
111 |
|
588
|
112 |
with open(os.path.join(dir1, '1'), 'w') as f_1:
|
|
113 |
f_1.write('Directory:%s\n' % self.root)
|
|
114 |
f_1.write('myfile1 TYPE=unknown format MD5=34dcda0d351c75e4942b55e1b2e2422g')
|
|
115 |
with open(os.path.join(dir2, '2'), 'w') as f_2:
|
|
116 |
f_2.write('Directory:%s\n' % self.root)
|
|
117 |
f_2.write('myfile1 TYPE=unknown format MD5=34dcda0d351c75e4542b55e1b2e2422g')
|
587
|
118 |
|
|
119 |
assert delta_zip.changedFiles(dir1, dir2) == [os.path.join(self.root, 'myfile1')]
|
|
120 |
|
|
121 |
def tearDown(self):
|
588
|
122 |
""" Restore path automatically called when all test have been run"""
|
587
|
123 |
os.chdir(self.cwd_backup) |