Allow confirm_import_feed to return None
[zeroinstall.git] / tests / basetest.py
blob663a46669cd0873a1ecda348ed08d4bc22d3ef2f
1 #!/usr/bin/env python2.5
2 import sys, tempfile, os, shutil, StringIO
3 import unittest
4 import logging
5 import warnings
7 # It's OK to test deprecated features
8 warnings.filterwarnings("ignore", category = DeprecationWarning)
10 # Catch silly mistakes...
11 os.environ['HOME'] = '/home/idontexist'
13 sys.path.insert(0, '..')
14 from zeroinstall.injector import qdom
15 from zeroinstall.injector import iface_cache, download, distro
16 from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False
17 from zeroinstall import support, helpers
18 from zeroinstall.support import basedir
20 dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg')
22 empty_feed = qdom.parse(StringIO.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
23 <name>Empty</name>
24 <summary>just for testing</summary>
25 </interface>"""))
27 mydir = os.path.dirname(__file__)
29 # Catch us trying to run the GUI and return a dummy string instead
30 old_execvp = os.execvp
31 def test_execvp(prog, args):
32 if prog.endswith('/0launch-gui'):
33 prog = os.path.join(mydir, 'test-gui')
34 return old_execvp(prog, args)
36 os.execvp = test_execvp
38 class BaseTest(unittest.TestCase):
39 def setUp(self):
40 self.config_home = tempfile.mktemp()
41 self.cache_home = tempfile.mktemp()
42 self.cache_system = tempfile.mktemp()
43 self.gnupg_home = tempfile.mktemp()
44 os.environ['GNUPGHOME'] = self.gnupg_home
45 os.environ['XDG_CONFIG_HOME'] = self.config_home
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)
69 def tearDown(self):
70 shutil.rmtree(self.config_home)
71 support.ro_rmtree(self.cache_home)
72 shutil.rmtree(self.cache_system)
73 shutil.rmtree(self.gnupg_home)
75 os.environ['PATH'] = self.old_path