1 #!/usr/bin/env python2.4
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 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
.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
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
)
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