Updated unit-tests and fixed some bugs they found.
[0release.git] / tests / testrelease.py
blob77170f3ec0f4de28fa27a7f1f22274a28bc76ee9
1 #!/usr/bin/env python2.5
2 # Copyright (C) 2007, Thomas Leonard
3 # See the README file for details, or visit http://0install.net.
4 import sys, os, shutil, tempfile, subprocess
5 import unittest
7 sys.path.insert(0, '..')
9 import support
11 mydir = os.path.realpath(os.path.dirname(__file__))
12 release_feed = mydir + '/../0release.xml'
13 test_repo = mydir + '/test-repo.tgz'
14 test_gpg = mydir + '/gpg.tgz'
16 class TestRelease(unittest.TestCase):
17 def setUp(self):
18 self.tmp = tempfile.mkdtemp(prefix = '0release-')
19 os.chdir(self.tmp)
20 support.check_call(['tar', 'xzf', test_repo])
21 support.check_call(['tar', 'xzf', test_gpg])
22 os.mkdir('releases')
23 os.environ['GNUPGHOME'] = self.tmp + '/gpg'
25 def tearDown(self):
26 os.chdir(mydir)
27 shutil.rmtree(self.tmp)
29 def testSimple(self):
30 os.chdir('releases')
31 support.check_call(['0launch', release_feed, '../hello/HelloWorld.xml'])
32 assert os.path.isfile('make-release')
34 lines = file('make-release').readlines()
35 lines[lines.index('ARCHIVE_DIR_PUBLIC_URL=\n')] = 'ARCHIVE_DIR_PUBLIC_URL=http://TESTING/releases\n'
36 s = file('make-release', 'w')
37 s.write(''.join(lines))
38 s.close()
40 child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin = subprocess.PIPE)
41 unused, unused = child.communicate('\nP\n\n')
42 assert child.returncode == 0
44 child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin = subprocess.PIPE)
45 unused, unused = child.communicate('\nP\n\n')
46 assert child.returncode == 0
48 assert 'Prints "Hello World"' in file('changelog-0.1').read()
49 assert 'Prints "Hello World"' not in file('changelog-0.2').read()
51 suite = unittest.makeSuite(TestRelease)
52 if __name__ == '__main__':
53 sys.argv.append('-v')
54 unittest.main()