Added --license option
[deb2zero.git] / tests / testall.py
blob377af68d6e06b92c746c0ed6fa605eed28f4deb4
1 #!/usr/bin/env python
3 import sys, os
4 import unittest
5 import subprocess
6 import shutil, tempfile
8 from zeroinstall import support
9 from zeroinstall.zerostore import unpack
11 mydir = os.path.dirname(__file__)
12 pkg2zero = os.path.join(mydir, '..', 'pkg2zero')
14 def run(args, **kwargs):
15 child = subprocess.Popen([pkg2zero] + args, stdout = subprocess.PIPE, stderr = subprocess.PIPE, stdin = subprocess.PIPE, **kwargs)
16 return child.communicate("\n\n")
18 TEST_DATA = os.environ["TEST_DATA"]
19 def testdata(path):
20 return os.path.join(TEST_DATA, path)
22 class TestAll(unittest.TestCase):
23 def setUp(self):
24 self.tmpdir = tempfile.mkdtemp('pkg2zero')
25 os.environ['HOME'] = self.tmpdir
26 os.environ['PATH'] = mydir + ':' + os.environ['PATH']
28 def tearDown(self):
29 support.ro_rmtree(self.tmpdir)
31 def testHelp(self):
32 cout, cerr = run(["--help"])
33 assert 'show this help message and exit' in cout, cout
34 assert not cerr, cerr
36 def testDeb(self):
37 target = os.path.join(self.tmpdir, 'netcat.xml')
38 cout, cerr = run(["http://ftp.uk.debian.org/debian/pool/main/n/netcat/netcat-traditional_1.10-38_i386.deb", target])
39 assert 'Added version 1.10-38 to ' in cout, (cout, cerr)
40 assert 'Mappings file not found' in cerr
41 assert 'no SHA-1' in cerr
43 cout, cerr = run(["http://ftp.uk.debian.org/debian/pool/main/n/netcat/netcat-traditional_1.10-38_i386.deb", target])
44 assert 'already contains an implementation with this digest' in cerr
46 child = subprocess.Popen(['0launch', target, '-h'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
47 cout, cerr = child.communicate()
48 assert 'connect to somewhere' in cerr, cerr
49 assert not cout, cout
51 def testDebTarball(self):
52 deb_file = "netcat-traditional_1.10-38_i386.deb"
53 build_dir = os.path.join(self.tmpdir, 'build')
54 os.mkdir(build_dir)
55 unpack.unpack_archive(deb_file, open(deb_file), destdir = build_dir)
56 tar_file = "netcat-traditional.tar.bz2"
57 subprocess.check_call(['tar', 'cjf', tar_file, 'build'], cwd = self.tmpdir)
59 target = os.path.join(self.tmpdir, 'netcat.xml')
60 cout, cerr = run(['--archive-extract=build', '--archive-url', "http://localhost/archives/" + tar_file, os.path.abspath(deb_file), target], cwd = self.tmpdir)
61 assert 'Added version 1.10-38 to ' in cout, (cout, cerr)
62 assert 'Mappings file not found' in cerr
63 assert 'no SHA-1' in cerr
65 child = subprocess.Popen(['0launch', target, '-h'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
66 cout, cerr = child.communicate()
67 assert 'connect to somewhere' in cerr, cerr
68 assert not cout, cout
70 def testRPM(self):
71 target = os.path.join(self.tmpdir, 'time.xml')
72 cout, cerr = run(['-r', testdata('repodata/repomd.xml'), "http://mirror.centos.org/centos/5/os/i386/CentOS/time-1.7-27.2.2.i386.rpm", target])
73 assert 'Added version 1.7 to ' in cout, (cout, cerr)
74 assert 'Mappings file not found' in cerr
75 assert 'no SHA-1' in cerr
77 child = subprocess.Popen(['0launch', target, 'echo', 'hi'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
78 cout, cerr = child.communicate()
79 assert 'hi' in cout, cout
80 assert 'pagefaults' in cerr, cerr
82 def testRepoDeb(self):
83 target = os.path.join(self.tmpdir, 'netcat.xml')
84 cout, cerr = run(["netcat-traditional", '--packages-file', testdata('Packages.bz2'), target])
85 assert 'Added version 1.10-38 to ' in cout, (cout, cerr)
86 assert 'Mappings file not found' in cerr
87 assert "Package's digest matches value in reposistory metadata" in cout, (cout, cerr)
89 child = subprocess.Popen(['0launch', target, '-h'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
90 cout, cerr = child.communicate()
91 assert 'connect to somewhere' in cerr, cerr
92 assert not cout, cout
95 def testRepoRPM(self):
96 target = os.path.join(self.tmpdir, 'time.xml')
97 cout, cerr = run(["time", '--repomd-file', testdata('repodata/repomd.xml'), target])
98 assert 'Added version 1.7 to ' in cout, (cout, cerr)
99 assert 'Mappings file not found' in cerr
100 assert "Package's digest matches value in reposistory metadata" in cout, (cout, cerr)
102 child = subprocess.Popen(['0launch', target, 'echo', 'hi'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
103 cout, cerr = child.communicate()
104 assert 'hi' in cout, cout
105 assert 'pagefaults' in cerr, cerr
107 if __name__ == '__main__':
108 sys.argv.append('-v')
109 unittest.main()