Fixed name of unit-test class
[0export.git] / test.py
blob84035a5e59ab5d043e99aab28a0950fad916b4e8
1 #!/usr/bin/env python
2 import sys, tempfile, os, subprocess
3 import unittest
5 zeroinstall_dir = os.environ.get('0EXPORT_ZEROINSTALL', None)
6 if zeroinstall_dir:
7 sys.path.insert(1, zeroinstall_dir)
9 from zeroinstall.support import ro_rmtree
11 my_dir = os.path.dirname(os.path.abspath(__file__))
13 export_bin = os.path.join(my_dir, '0export')
15 PUBLISH_URI = 'http://0install.net/2006/interfaces/0publish'
17 class TestExport(unittest.TestCase):
18 def setUp(self):
19 os.chdir('/')
20 self.tmpdir = tempfile.mkdtemp(prefix = '0export-test-')
22 # tmpdir is used as $HOME when running the bundle...
23 config_dir = os.path.join(self.tmpdir, '.config', '0install.net', 'injector')
24 os.makedirs(config_dir)
25 stream = open(os.path.join(config_dir, 'global'), 'w')
26 stream.write('[global]\n'
27 'freshness = -1\n'
28 'help_with_testing = False\n'
29 'network_use = off-line\n')
30 stream.close()
32 def tearDown(self):
33 ro_rmtree(self.tmpdir)
35 def testSimple(self):
36 setup_sh = os.path.join(self.tmpdir, 'setup.sh')
37 subprocess.check_call([sys.executable, export_bin, setup_sh, PUBLISH_URI])
39 env = {
40 'HOME': self.tmpdir,
41 'http_proxy' : 'localhost:1111', # Detect accidental network access
42 'PATH': '/bin:/usr/bin:' + os.path.dirname(sys.executable),
45 child = subprocess.Popen([setup_sh, '--help'], env = env, stdout = subprocess.PIPE)
46 cout, unused = child.communicate()
47 assert child.wait() == 0
48 assert 'Run self-extracting installer' in cout
50 child = subprocess.Popen([setup_sh, '--', '--help'], env = env, stdout = subprocess.PIPE)
51 cout, unused = child.communicate()
52 assert child.wait() == 0
53 assert '--xmlsign' in cout
55 suite = unittest.makeSuite(TestExport)
56 if __name__ == '__main__':
57 unittest.main()