2 import sys
, tempfile
, os
, shutil
, StringIO
6 warnings
.filterwarnings("ignore", message
= 'The CObject type')
8 # Catch silly mistakes...
9 os
.environ
['HOME'] = '/home/idontexist'
10 os
.environ
['LANGUAGE'] = 'C'
12 sys
.path
.insert(0, '..')
13 from zeroinstall
.injector
import qdom
14 from zeroinstall
.injector
import iface_cache
, download
, distro
, model
15 from zeroinstall
.zerostore
import Store
; Store
._add
_with
_helper
= lambda *unused
: False
16 from zeroinstall
import support
, helpers
17 from zeroinstall
.support
import basedir
19 dpkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'dpkg')
21 empty_feed
= qdom
.parse(StringIO
.StringIO("""<interface xmlns='http://zero-install.sourceforge.net/2004/injector/interface'>
23 <summary>just for testing</summary>
27 sys
.modules
['dbus'] = my_dbus
28 sys
.modules
['dbus.glib'] = my_dbus
29 my_dbus
.types
= my_dbus
30 sys
.modules
['dbus.types'] = my_dbus
31 sys
.modules
['dbus.mainloop'] = my_dbus
32 sys
.modules
['dbus.mainloop.glib'] = my_dbus
34 mydir
= os
.path
.dirname(__file__
)
36 # Catch us trying to run the GUI and return a dummy string instead
37 old_execvp
= os
.execvp
38 def test_execvp(prog
, args
):
39 if prog
.endswith('/0launch-gui'):
40 prog
= os
.path
.join(mydir
, 'test-gui')
41 return old_execvp(prog
, args
)
43 os
.execvp
= test_execvp
45 test_locale
= (None, None)
48 LC_ALL
= 0 # Note: LC_MESSAGES not present on Windows
49 def getlocale(self
, x
):
51 model
.locale
= TestLocale()
53 class DummyPackageKit
:
56 def get_candidates(self
, package
, factory
, prefix
):
59 class BaseTest(unittest
.TestCase
):
61 warnings
.resetwarnings()
62 self
.config_home
= tempfile
.mktemp()
63 self
.cache_home
= tempfile
.mktemp()
64 self
.cache_system
= tempfile
.mktemp()
65 self
.gnupg_home
= tempfile
.mktemp()
66 os
.environ
['GNUPGHOME'] = self
.gnupg_home
67 os
.environ
['XDG_CONFIG_HOME'] = self
.config_home
68 os
.environ
['XDG_CONFIG_DIRS'] = ''
69 os
.environ
['XDG_CACHE_HOME'] = self
.cache_home
70 os
.environ
['XDG_CACHE_DIRS'] = self
.cache_system
72 assert basedir
.xdg_config_home
== self
.config_home
73 iface_cache
.iface_cache
.__init
__()
75 os
.mkdir(self
.config_home
, 0700)
76 os
.mkdir(self
.cache_home
, 0700)
77 os
.mkdir(self
.cache_system
, 0500)
78 os
.mkdir(self
.gnupg_home
, 0700)
80 if os
.environ
.has_key('DISPLAY'):
81 del os
.environ
['DISPLAY']
83 logging
.getLogger().setLevel(logging
.WARN
)
85 download
._downloads
= {}
87 self
.old_path
= os
.environ
['PATH']
88 os
.environ
['PATH'] = dpkgdir
+ ':' + self
.old_path
90 distro
._host
_distribution
= distro
.DebianDistribution(dpkgdir
+ '/status',
91 dpkgdir
+ '/pkgcache.bin')
92 distro
._host
_distribution
._packagekit
= DummyPackageKit()
94 my_dbus
.system_services
= {}
97 shutil
.rmtree(self
.config_home
)
98 support
.ro_rmtree(self
.cache_home
)
99 shutil
.rmtree(self
.cache_system
)
100 shutil
.rmtree(self
.gnupg_home
)
102 os
.environ
['PATH'] = self
.old_path