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
, handler
, policy
15 from zeroinstall
.zerostore
import Store
, Stores
; 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 DummyHandler(handler
.Handler
):
60 __slots__
= ['ex', 'tb']
63 handler
.Handler
.__init
__(self
)
66 def wait_for_blocker(self
, blocker
):
68 handler
.Handler
.wait_for_blocker(self
, blocker
)
70 raise self
.ex
, None, self
.tb
72 def report_error(self
, ex
, tb
= None):
73 assert self
.ex
is None, self
.ex
78 #traceback.print_exc()
81 def download_impls(self
, impls
, stores
):
82 assert impls
== [], impls
86 help_test_new_versions
= False
87 network_use
= model
.network_full
90 self
.iface_cache
= iface_cache
.IfaceCache()
91 self
.handler
= DummyHandler()
92 self
.stores
= Stores()
93 self
.fetcher
= TestFetcher()
95 class BaseTest(unittest
.TestCase
):
97 warnings
.resetwarnings()
99 self
.config_home
= tempfile
.mktemp()
100 self
.cache_home
= tempfile
.mktemp()
101 self
.cache_system
= tempfile
.mktemp()
102 self
.gnupg_home
= tempfile
.mktemp()
103 os
.environ
['GNUPGHOME'] = self
.gnupg_home
104 os
.environ
['XDG_CONFIG_HOME'] = self
.config_home
105 os
.environ
['XDG_CONFIG_DIRS'] = ''
106 os
.environ
['XDG_CACHE_HOME'] = self
.cache_home
107 os
.environ
['XDG_CACHE_DIRS'] = self
.cache_system
109 assert basedir
.xdg_config_home
== self
.config_home
111 os
.mkdir(self
.config_home
, 0700)
112 os
.mkdir(self
.cache_home
, 0700)
113 os
.mkdir(self
.cache_system
, 0500)
114 os
.mkdir(self
.gnupg_home
, 0700)
116 if os
.environ
.has_key('DISPLAY'):
117 del os
.environ
['DISPLAY']
119 self
.config
= TestConfig()
120 policy
._config
= self
.config
# XXX
122 logging
.getLogger().setLevel(logging
.WARN
)
124 download
._downloads
= {}
126 self
.old_path
= os
.environ
['PATH']
127 os
.environ
['PATH'] = dpkgdir
+ ':' + self
.old_path
129 distro
._host
_distribution
= distro
.DebianDistribution(dpkgdir
+ '/status',
130 dpkgdir
+ '/pkgcache.bin')
131 distro
._host
_distribution
._packagekit
= DummyPackageKit()
133 my_dbus
.system_services
= {}
136 assert self
.config
.handler
.ex
is None, self
.config
.handler
.ex
138 shutil
.rmtree(self
.config_home
)
139 support
.ro_rmtree(self
.cache_home
)
140 shutil
.rmtree(self
.cache_system
)
141 shutil
.rmtree(self
.gnupg_home
)
143 os
.environ
['PATH'] = self
.old_path