Better exception handling in GUI.
[zeroinstall/zeroinstall-rsl.git] / tests / basetest.py
blobbfcfc2ffa86b3bdf03f5659ac8de3f3ef0a4fdd7
1 #!/usr/bin/env python2.4
2 import sys, tempfile, os, shutil, StringIO
3 import unittest
4 import logging
6 # Catch silly mistakes...
7 os.environ['HOME'] = '/home/idontexist'
9 sys.path.insert(0, '..')
10 from zeroinstall.injector import trust, autopolicy, namespaces, qdom
11 from zeroinstall.injector import model, iface_cache, cli, download, writer, distro
12 from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False
13 from zeroinstall import support
14 from zeroinstall.support import basedir
16 dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg')
18 empty_feed = qdom.parse(StringIO.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
19 <name>Empty</name>
20 <summary>just for testing</summary>
21 </interface>"""))
23 class BaseTest(unittest.TestCase):
24 def setUp(self):
25 self.config_home = tempfile.mktemp()
26 self.cache_home = tempfile.mktemp()
27 self.cache_system = tempfile.mktemp()
28 self.gnupg_home = tempfile.mktemp()
29 os.environ['GNUPGHOME'] = self.gnupg_home
30 os.environ['XDG_CONFIG_HOME'] = self.config_home
31 os.environ['XDG_CACHE_HOME'] = self.cache_home
32 os.environ['XDG_CACHE_DIRS'] = self.cache_system
33 reload(basedir)
34 assert basedir.xdg_config_home == self.config_home
35 iface_cache.iface_cache.__init__()
37 os.mkdir(self.config_home, 0700)
38 os.mkdir(self.cache_home, 0700)
39 os.mkdir(self.cache_system, 0500)
40 os.mkdir(self.gnupg_home, 0700)
42 if os.environ.has_key('DISPLAY'):
43 del os.environ['DISPLAY']
44 namespaces.injector_gui_uri = os.path.join(os.path.dirname(__file__), 'test-gui.xml')
46 logging.getLogger().setLevel(logging.WARN)
48 download._downloads = {}
50 self.old_path = os.environ['PATH']
51 os.environ['PATH'] = dpkgdir + ':' + self.old_path
53 distro._host_distribution = distro.DebianDistribution(dpkgdir)
55 def tearDown(self):
56 shutil.rmtree(self.config_home)
57 support.ro_rmtree(self.cache_home)
58 shutil.rmtree(self.cache_system)
59 shutil.rmtree(self.gnupg_home)
61 os.environ['PATH'] = self.old_path