1 #!/usr/bin/env python2.4
2 import sys
, tempfile
, os
, 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 namespaces
, 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
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 class BaseTest(unittest
.TestCase
):
29 self
._on
_teardown
= []
30 self
.config_home
= self
.make_temp_dir()
31 self
.cache_home
= self
.make_temp_dir()
32 self
.cache_system
= self
.make_temp_dir()
33 self
.gnupg_home
= self
.make_temp_dir()
34 os
.chmod(self
.cache_system
, 0500) # Read-only
35 os
.environ
['GNUPGHOME'] = self
.gnupg_home
36 os
.environ
['XDG_CONFIG_HOME'] = self
.config_home
37 os
.environ
['XDG_CACHE_HOME'] = self
.cache_home
38 os
.environ
['XDG_CACHE_DIRS'] = self
.cache_system
40 assert basedir
.xdg_config_home
== self
.config_home
41 iface_cache
.iface_cache
.__init
__()
43 if os
.environ
.has_key('DISPLAY'):
44 del os
.environ
['DISPLAY']
45 namespaces
.injector_gui_uri
= os
.path
.join(os
.path
.dirname(__file__
), 'test-gui.xml')
47 logging
.getLogger().setLevel(logging
.WARN
)
49 download
._downloads
= {}
51 self
.old_path
= os
.environ
['PATH']
52 os
.environ
['PATH'] = dpkgdir
+ ':' + self
.old_path
54 distro
._host
_distribution
= distro
.DebianDistribution(dpkgdir
)
56 def make_temp_dir(self
):
57 temp_dir
= tempfile
.mkdtemp(
58 prefix
="tmp-%s-" % self
.__class
__.__name
__)
60 support
.ro_rmtree(temp_dir
)
61 self
._on
_teardown
.append(tear_down
)
65 os
.environ
['PATH'] = self
.old_path
66 for func
in reversed(self
._on
_teardown
):