2 import sys
, tempfile
, os
, shutil
, StringIO
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'>
24 <summary>just for testing</summary>
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
):
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_CONFIG_DIRS'] = ''
47 os
.environ
['XDG_CACHE_HOME'] = self
.cache_home
48 os
.environ
['XDG_CACHE_DIRS'] = self
.cache_system
50 assert basedir
.xdg_config_home
== self
.config_home
51 iface_cache
.iface_cache
.__init
__()
53 os
.mkdir(self
.config_home
, 0700)
54 os
.mkdir(self
.cache_home
, 0700)
55 os
.mkdir(self
.cache_system
, 0500)
56 os
.mkdir(self
.gnupg_home
, 0700)
58 if os
.environ
.has_key('DISPLAY'):
59 del os
.environ
['DISPLAY']
61 logging
.getLogger().setLevel(logging
.WARN
)
63 download
._downloads
= {}
65 self
.old_path
= os
.environ
['PATH']
66 os
.environ
['PATH'] = dpkgdir
+ ':' + self
.old_path
68 distro
._host
_distribution
= distro
.DebianDistribution(dpkgdir
+ '/status',
69 dpkgdir
+ '/pkgcache.bin')
72 shutil
.rmtree(self
.config_home
)
73 support
.ro_rmtree(self
.cache_home
)
74 shutil
.rmtree(self
.cache_system
)
75 shutil
.rmtree(self
.gnupg_home
)
77 os
.environ
['PATH'] = self
.old_path