2 import sys
, tempfile
, os
, shutil
, StringIO
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'>
22 <summary>just for testing</summary>
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
):
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
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')
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