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
6 from zeroinstall
.injector
import model
, qdom
8 sys
.path
.insert(0, '..')
12 mydir
= os
.path
.realpath(os
.path
.dirname(__file__
))
13 release_feed
= mydir
+ '/../0release.xml'
14 test_repo
= mydir
+ '/test-repo.tgz'
15 test_repo_actions
= mydir
+ '/test-repo-actions.tgz'
16 test_repo_c
= mydir
+ '/c-prog.tgz'
17 test_gpg
= mydir
+ '/gpg.tgz'
19 def make_releases_dir(src_feed
= '../hello/HelloWorld.xml', auto_upload
= False):
21 support
.check_call(['0launch', release_feed
, src_feed
])
22 assert os
.path
.isfile('make-release')
24 lines
= file('make-release').readlines()
25 lines
[lines
.index('ARCHIVE_DIR_PUBLIC_URL=\n')] = 'ARCHIVE_DIR_PUBLIC_URL=http://TESTING/releases\n'
29 lines
[lines
.index('ARCHIVE_UPLOAD_COMMAND=\n')] = 'ARCHIVE_UPLOAD_COMMAND=\'cp "$@" ../archives/\'\n'
31 s
= file('make-release', 'w')
32 s
.write(''.join(lines
))
35 class TestRelease(unittest
.TestCase
):
37 self
.tmp
= tempfile
.mkdtemp(prefix
= '0release-')
39 support
.check_call(['tar', 'xzf', test_gpg
])
41 os
.environ
['GNUPGHOME'] = self
.tmp
+ '/gpg'
42 os
.chmod(os
.environ
['GNUPGHOME'], 0700)
46 shutil
.rmtree(self
.tmp
)
49 support
.check_call(['tar', 'xzf', test_repo
])
52 child
= subprocess
.Popen(['./make-release', '-k', 'Testing'], stdin
= subprocess
.PIPE
)
53 unused
, unused
= child
.communicate('\nP\n\n')
54 assert child
.returncode
== 0
56 child
= subprocess
.Popen(['./make-release', '-k', 'Testing'], stdin
= subprocess
.PIPE
)
57 unused
, unused
= child
.communicate('\nP\n\n')
58 assert child
.returncode
== 0
60 assert 'Prints "Hello World"' in file('0.1/changelog-0.1').read()
61 assert 'Prints "Hello World"' not in file('0.2/changelog-0.2').read()
63 def testUncommitted(self
):
64 support
.check_call(['tar', 'xzf', test_repo_actions
])
67 child
= subprocess
.Popen(['./make-release', '-k', 'Testing'], stdin
= subprocess
.PIPE
, stderr
= subprocess
.PIPE
)
68 unused
, stderr
= child
.communicate()
69 assert child
.returncode
!= 0
70 assert "Uncommitted changes!" in stderr
72 def testActions(self
):
73 support
.check_call(['tar', 'xzf', test_repo_actions
])
75 support
.check_call(['git', 'commit', '-a', '-m', 'Added release instructions'])
79 assert "version = '0.2'\n" not in file('../hello/hello.py').read()
81 child
= subprocess
.Popen(['./make-release', '-k', 'Testing'], stdin
= subprocess
.PIPE
)
82 unused
, unused
= child
.communicate('\nP\n\n')
83 assert child
.returncode
== 0
85 assert "version = '0.2'\n" in file('../hello/hello.py').read()
87 def testBinaryRelease(self
):
88 support
.check_call(['tar', 'xzf', test_repo_c
])
89 make_releases_dir(src_feed
= '../c-prog/c-prog.xml', auto_upload
= True)
91 child
= subprocess
.Popen(['./make-release', '-k', 'Testing', '--builders=host'], stdin
= subprocess
.PIPE
)
92 unused
, unused
= child
.communicate('\nP\n\n')
93 assert child
.returncode
== 0
95 feed
= model
.ZeroInstallFeed(qdom
.parse(file('HelloWorld-in-C.xml')))
97 assert len(feed
.implementations
) == 2
98 src_impl
, = [x
for x
in feed
.implementations
.values() if x
.arch
== '*-src']
99 host_impl
, = [x
for x
in feed
.implementations
.values() if x
.arch
!= '*-src']
101 assert src_impl
.main
== None
102 assert host_impl
.main
== 'hello'
104 archives
= os
.listdir('archives')
105 assert os
.path
.basename(src_impl
.download_sources
[0].url
) in archives
107 host_download
= host_impl
.download_sources
[0]
108 host_archive
= os
.path
.basename(host_download
.url
)
109 assert host_archive
in archives
110 support
.check_call(['tar', 'xjf', os
.path
.join('archives', host_archive
)])
111 c
= subprocess
.Popen(['0launch', os
.path
.join(host_download
.extract
, '0install', 'helloworld-in-c-1.1.xml')], stdout
= subprocess
.PIPE
)
112 output
, _
= c
.communicate()
114 self
.assertEquals("Hello from C! (version 1.1)\n", output
)
117 suite
= unittest
.makeSuite(TestRelease
)
118 if __name__
== '__main__':
119 sys
.argv
.append('-v')