Updated tests for GIT 1.6
[0release.git] / tests / testrelease.py
blob2a0c9f75a43b607bccc05dbd31e8248888f67c7b
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_repo_actions = mydir + '/test-repo-actions.tgz'
15 test_gpg = mydir + '/gpg.tgz'
17 def make_releases_dir():
18 os.chdir('releases')
19 support.check_call(['0launch', release_feed, '../hello/HelloWorld.xml'])
20 assert os.path.isfile('make-release')
22 lines = file('make-release').readlines()
23 lines[lines.index('ARCHIVE_DIR_PUBLIC_URL=\n')] = 'ARCHIVE_DIR_PUBLIC_URL=http://TESTING/releases\n'
24 s = file('make-release', 'w')
25 s.write(''.join(lines))
26 s.close()
28 class TestRelease(unittest.TestCase):
29 def setUp(self):
30 self.tmp = tempfile.mkdtemp(prefix = '0release-')
31 os.chdir(self.tmp)
32 support.check_call(['tar', 'xzf', test_gpg])
33 os.mkdir('releases')
34 os.environ['GNUPGHOME'] = self.tmp + '/gpg'
35 os.chmod(os.environ['GNUPGHOME'], 0700)
37 def tearDown(self):
38 os.chdir(mydir)
39 shutil.rmtree(self.tmp)
41 def testSimple(self):
42 support.check_call(['tar', 'xzf', test_repo])
43 make_releases_dir()
45 child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin = subprocess.PIPE)
46 unused, unused = child.communicate('\nP\n\n')
47 assert child.returncode == 0
49 child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin = subprocess.PIPE)
50 unused, unused = child.communicate('\nP\n\n')
51 assert child.returncode == 0
53 assert 'Prints "Hello World"' in file('0.1/changelog-0.1').read()
54 assert 'Prints "Hello World"' not in file('0.2/changelog-0.2').read()
56 def testUncommitted(self):
57 support.check_call(['tar', 'xzf', test_repo_actions])
58 make_releases_dir()
60 child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin = subprocess.PIPE, stderr = subprocess.PIPE)
61 unused, stderr = child.communicate()
62 assert child.returncode != 0
63 assert "Uncommitted changes!" in stderr
65 def testActions(self):
66 support.check_call(['tar', 'xzf', test_repo_actions])
67 os.chdir('hello')
68 support.check_call(['git', 'commit', '-a', '-m', 'Added release instructions'])
69 os.chdir('..')
70 make_releases_dir()
72 assert "version = '0.2'\n" not in file('../hello/hello.py').read()
74 child = subprocess.Popen(['./make-release', '-k', 'Testing'], stdin = subprocess.PIPE)
75 unused, unused = child.communicate('\nP\n\n')
76 assert child.returncode == 0
78 assert "version = '0.2'\n" in file('../hello/hello.py').read()
80 suite = unittest.makeSuite(TestRelease)
81 if __name__ == '__main__':
82 sys.argv.append('-v')
83 unittest.main()