1 #!/usr/bin/env python2.4
2 from basetest
import BaseTest
3 import sys
, tempfile
, os
, shutil
6 sys
.path
.insert(0, '..')
7 from zeroinstall
.zerostore
import manifest
, BadDigest
9 class TestManifest(BaseTest
):
12 self
.tmpdir
= tempfile
.mkdtemp(prefix
= 'test-manifest')
15 BaseTest
.tearDown(self
)
16 shutil
.rmtree(self
.tmpdir
)
18 def testUnknownAlgorithm(self
):
20 manifest
.get_algorithm('unknown')
27 '\n'.join(manifest
.generate_manifest(self
.tmpdir
)))
29 def write(self
, path
, contents
, time
= None):
30 assert not path
.startswith('/')
31 myfile
= os
.path
.join(self
.tmpdir
, path
)
32 stream
= file(myfile
, 'w')
33 stream
.write(contents
)
36 os
.utime(myfile
, (time
, time
))
40 mydir
= os
.path
.join(self
.tmpdir
, 'MyDir')
42 myfile
= self
.write('MyDir/Hello', 'Hello World', 30)
43 myexec
= self
.write('MyDir/Run me', 'Bang!', 40)
44 os
.symlink('Hello', os
.path
.join(self
.tmpdir
, 'MyDir/Sym link'))
45 os
.chmod(myexec
, 0700)
46 os
.utime(mydir
, (10, 20))
49 'F 0a4d55a8d778e5022fab701977c5d840bbc486d0 30 11 Hello',
50 'X 4001b8c42ddfb61c453d04930e8ce78fb3a40bc8 40 5 Run me',
51 'S f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 5 Sym link'],
52 list(manifest
.generate_manifest(self
.tmpdir
)))
54 def testNewSHA1(self
):
55 mydir
= os
.path
.join(self
.tmpdir
, 'MyDir')
57 myfile
= self
.write('MyDir/Hello', 'Hello World', 30)
58 myexec
= self
.write('MyDir/Run me', 'Bang!', 40)
59 os
.symlink('Hello', os
.path
.join(self
.tmpdir
, 'MyDir/Sym link'))
60 os
.chmod(myexec
, 0700)
61 os
.utime(mydir
, (10, 20))
64 'F 0a4d55a8d778e5022fab701977c5d840bbc486d0 30 11 Hello',
65 'X 4001b8c42ddfb61c453d04930e8ce78fb3a40bc8 40 5 Run me',
66 'S f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 5 Sym link'],
67 list(manifest
.generate_manifest(self
.tmpdir
, alg
= 'sha1new')))
69 def testOrderingSHA1(self
):
70 mydir
= os
.path
.join(self
.tmpdir
, 'Dir')
72 myfile
= self
.write('Hello', 'Hello World', 30)
73 myfile
= self
.write('Dir/Hello', 'Hello World', 30)
74 os
.utime(mydir
, (10, 20))
76 'F 0a4d55a8d778e5022fab701977c5d840bbc486d0 30 11 Hello',
78 'F 0a4d55a8d778e5022fab701977c5d840bbc486d0 30 11 Hello'],
79 list(manifest
.generate_manifest(self
.tmpdir
, alg
= 'sha1new')))
81 def testNewSHA256(self
):
82 mydir
= os
.path
.join(self
.tmpdir
, 'MyDir')
84 myfile
= self
.write('MyDir/Hello', 'Hello World', 30)
85 myexec
= self
.write('MyDir/Run me', 'Bang!', 40)
86 os
.symlink('Hello', os
.path
.join(self
.tmpdir
, 'MyDir/Sym link'))
87 os
.chmod(myexec
, 0700)
90 'F a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e 30 11 Hello',
91 'X 640628586b08f8ed3910bd1e75ba02818959e843b54efafb9c2260a1f77e3ddf 40 5 Run me',
92 'S 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969 5 Sym link'],
93 list(manifest
.generate_manifest(self
.tmpdir
, alg
= 'sha256')))
95 def testOrdering(self
):
96 mydir
= os
.path
.join(self
.tmpdir
, 'Dir')
98 myfile
= self
.write('Hello', 'Hello World', 30)
99 os
.utime(mydir
, (10, 20))
101 'F a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e 30 11 Hello',
103 list(manifest
.generate_manifest(self
.tmpdir
, alg
='sha256')))
105 def testParseManifest(self
):
106 self
.assertEquals({}, manifest
._parse
_manifest
(''))
107 parsed
= manifest
._parse
_manifest
('F e3d5983c3dfd415af24772b48276d16122fe5a87 1172429666 2980 README\n'
108 'X 8a1f3c5f416f0e63140928102c44cd16ec2c6100 1172429666 5816 install.sh\n'
110 'S 2b37e4457a1a38cfab89391ce1bfbe4dc5473fc3 26 mime-application:x-java-archive.png\n')
113 assert keys
== ['0install', '0install/mime-application:x-java-archive.png', 'README', 'install.sh']
114 for bad
in ['Hello', 'D bob\n', 'D /bob\nD /bob\n']:
116 manifest
._parse
_manifest
(bad
)
121 suite
= unittest
.makeSuite(TestManifest
)
122 if __name__
== '__main__':
123 sys
.argv
.append('-v')