Run unit-tests in C locale
[zeroinstall.git] / tests / basetest.py
blobe4b7fa18b79665da05f77ae3cc69845e39db206b
1 #!/usr/bin/env python
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'
12 os.environ['LANGUAGE'] = 'C'
14 sys.path.insert(0, '..')
15 from zeroinstall.injector import qdom
16 from zeroinstall.injector import iface_cache, download, distro
17 from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False
18 from zeroinstall import support, helpers
19 from zeroinstall.support import basedir
21 dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg')
23 empty_feed = qdom.parse(StringIO.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
24 <name>Empty</name>
25 <summary>just for testing</summary>
26 </interface>"""))
28 mydir = os.path.dirname(__file__)
30 # Catch us trying to run the GUI and return a dummy string instead
31 old_execvp = os.execvp
32 def test_execvp(prog, args):
33 if prog.endswith('/0launch-gui'):
34 prog = os.path.join(mydir, 'test-gui')
35 return old_execvp(prog, args)
37 os.execvp = test_execvp
39 class BaseTest(unittest.TestCase):
40 def setUp(self):
41 self.config_home = tempfile.mktemp()
42 self.cache_home = tempfile.mktemp()
43 self.cache_system = tempfile.mktemp()
44 self.gnupg_home = tempfile.mktemp()
45 os.environ['GNUPGHOME'] = self.gnupg_home
46 os.environ['XDG_CONFIG_HOME'] = self.config_home
47 os.environ['XDG_CONFIG_DIRS'] = ''
48 os.environ['XDG_CACHE_HOME'] = self.cache_home
49 os.environ['XDG_CACHE_DIRS'] = self.cache_system
50 reload(basedir)
51 assert basedir.xdg_config_home == self.config_home
52 iface_cache.iface_cache.__init__()
54 os.mkdir(self.config_home, 0700)
55 os.mkdir(self.cache_home, 0700)
56 os.mkdir(self.cache_system, 0500)
57 os.mkdir(self.gnupg_home, 0700)
59 if os.environ.has_key('DISPLAY'):
60 del os.environ['DISPLAY']
62 logging.getLogger().setLevel(logging.WARN)
64 download._downloads = {}
66 self.old_path = os.environ['PATH']
67 os.environ['PATH'] = dpkgdir + ':' + self.old_path
69 distro._host_distribution = distro.DebianDistribution(dpkgdir + '/status',
70 dpkgdir + '/pkgcache.bin')
72 def tearDown(self):
73 shutil.rmtree(self.config_home)
74 support.ro_rmtree(self.cache_home)
75 shutil.rmtree(self.cache_system)
76 shutil.rmtree(self.gnupg_home)
78 os.environ['PATH'] = self.old_path