API changes: use Feed rather than Interface in many places
[zeroinstall/zeroinstall-afb.git] / tests / basetest.py
blob3ac845619da61c4065fd2acc2a25fd33e0ec6c7f
1 #!/usr/bin/env python
2 import sys, tempfile, os, shutil, StringIO
3 import unittest
4 import logging
5 import warnings
7 # Catch silly mistakes...
8 os.environ['HOME'] = '/home/idontexist'
9 os.environ['LANGUAGE'] = 'C'
11 sys.path.insert(0, '..')
12 from zeroinstall.injector import qdom
13 from zeroinstall.injector import iface_cache, download, distro
14 from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False
15 from zeroinstall import support, helpers
16 from zeroinstall.support import basedir
18 dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg')
20 empty_feed = qdom.parse(StringIO.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
21 <name>Empty</name>
22 <summary>just for testing</summary>
23 </interface>"""))
25 mydir = os.path.dirname(__file__)
27 # Catch us trying to run the GUI and return a dummy string instead
28 old_execvp = os.execvp
29 def test_execvp(prog, args):
30 if prog.endswith('/0launch-gui'):
31 prog = os.path.join(mydir, 'test-gui')
32 return old_execvp(prog, args)
34 os.execvp = test_execvp
36 class BaseTest(unittest.TestCase):
37 def setUp(self):
38 warnings.resetwarnings()
39 self.config_home = tempfile.mktemp()
40 self.cache_home = tempfile.mktemp()
41 self.cache_system = tempfile.mktemp()
42 self.gnupg_home = tempfile.mktemp()
43 os.environ['GNUPGHOME'] = self.gnupg_home
44 os.environ['XDG_CONFIG_HOME'] = self.config_home
45 os.environ['XDG_CONFIG_DIRS'] = ''
46 os.environ['XDG_CACHE_HOME'] = self.cache_home
47 os.environ['XDG_CACHE_DIRS'] = self.cache_system
48 reload(basedir)
49 assert basedir.xdg_config_home == self.config_home
50 iface_cache.iface_cache.__init__()
52 os.mkdir(self.config_home, 0700)
53 os.mkdir(self.cache_home, 0700)
54 os.mkdir(self.cache_system, 0500)
55 os.mkdir(self.gnupg_home, 0700)
57 if os.environ.has_key('DISPLAY'):
58 del os.environ['DISPLAY']
60 logging.getLogger().setLevel(logging.WARN)
62 download._downloads = {}
64 self.old_path = os.environ['PATH']
65 os.environ['PATH'] = dpkgdir + ':' + self.old_path
67 distro._host_distribution = distro.DebianDistribution(dpkgdir + '/status',
68 dpkgdir + '/pkgcache.bin')
70 def tearDown(self):
71 shutil.rmtree(self.config_home)
72 support.ro_rmtree(self.cache_home)
73 shutil.rmtree(self.cache_system)
74 shutil.rmtree(self.gnupg_home)
76 os.environ['PATH'] = self.old_path