Added --cpu and --os arguments to 0launch
[zeroinstall/zeroinstall-mseaborn.git] / tests / basetest.py
blob989d0e0565fa1fc0bfe4409f174db61ff3027431
1 #!/usr/bin/env python2.4
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 trust, autopolicy, namespaces, qdom
15 from zeroinstall.injector import model, iface_cache, cli, download, writer, distro
16 from zeroinstall.zerostore import Store; Store._add_with_helper = lambda *unused: False
17 from zeroinstall import support
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 class BaseTest(unittest.TestCase):
28 def setUp(self):
29 self.config_home = tempfile.mktemp()
30 self.cache_home = tempfile.mktemp()
31 self.cache_system = tempfile.mktemp()
32 self.gnupg_home = tempfile.mktemp()
33 os.environ['GNUPGHOME'] = self.gnupg_home
34 os.environ['XDG_CONFIG_HOME'] = self.config_home
35 os.environ['XDG_CACHE_HOME'] = self.cache_home
36 os.environ['XDG_CACHE_DIRS'] = self.cache_system
37 reload(basedir)
38 assert basedir.xdg_config_home == self.config_home
39 iface_cache.iface_cache.__init__()
41 os.mkdir(self.config_home, 0700)
42 os.mkdir(self.cache_home, 0700)
43 os.mkdir(self.cache_system, 0500)
44 os.mkdir(self.gnupg_home, 0700)
46 if os.environ.has_key('DISPLAY'):
47 del os.environ['DISPLAY']
48 namespaces.injector_gui_uri = os.path.join(os.path.dirname(__file__), 'test-gui.xml')
50 logging.getLogger().setLevel(logging.WARN)
52 download._downloads = {}
54 self.old_path = os.environ['PATH']
55 os.environ['PATH'] = dpkgdir + ':' + self.old_path
57 distro._host_distribution = distro.DebianDistribution(dpkgdir)
59 def tearDown(self):
60 shutil.rmtree(self.config_home)
61 support.ro_rmtree(self.cache_home)
62 shutil.rmtree(self.cache_system)
63 shutil.rmtree(self.gnupg_home)
65 os.environ['PATH'] = self.old_path