2 from basetest
import BaseTest
, empty_feed
, DummyPackageKit
3 import sys
, os
, tempfile
4 from StringIO
import StringIO
7 sys
.path
.insert(0, '..')
8 from zeroinstall
.injector
import distro
, model
, qdom
, iface_cache
, handler
10 def parse_impls(impls
):
11 xml
= """<?xml version="1.0" ?>
12 <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
14 <summary>Foo</summary>
15 <description>Foo</description>
17 </interface>""" % impls
18 element
= qdom
.parse(StringIO(xml
))
19 return model
.ZeroInstallFeed(element
, "myfeed.xml")
21 class TestDistro(BaseTest
):
24 self
.feed
= model
.ZeroInstallFeed(empty_feed
, local_path
= '/empty.xml')
27 BaseTest
.tearDown(self
)
30 src
= tempfile
.NamedTemporaryFile()
32 cache
= distro
.Cache('test-cache', src
.name
, 1)
33 self
.assertEqual(None, cache
.get("foo"))
35 self
.assertEqual("1", cache
.get("foo"))
37 self
.assertEqual("2", cache
.get("foo"))
40 cache
= distro
.Cache('test-cache', src
.name
, 1)
41 self
.assertEqual("2", cache
.get("foo"))
46 self
.assertEqual(None, cache
.get("foo"))
49 # new cache... (format change)
50 cache
= distro
.Cache('test-cache', src
.name
, 2)
51 self
.assertEqual(None, cache
.get("foo"))
56 def make_factory(self
, distro
):
57 def factory(id, only_if_missing
= False, installed
= True):
58 assert not only_if_missing
59 impl
= model
.DistributionImplementation(self
.feed
, id, distro
)
60 assert id not in self
.feed
.implementations
61 self
.feed
.implementations
[id] = impl
62 impl
.installed
= installed
66 def testDefault(self
):
67 host
= distro
.Distribution()
69 factory
= self
.make_factory(host
)
70 host
.get_package_info('gimp', factory
)
71 self
.assertEqual(self
.feed
.implementations
, {})
73 # Special case: we can always find a version of Python
74 master_feed
= model
.ZeroInstallFeed(None)
75 master_feed
.url
= 'http://repo.roscidus.com/python/python'
76 feed
= host
.get_feed(master_feed
)
77 self
.assertEqual(1, len(feed
.implementations
))
80 dpkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'dpkg')
81 host
= distro
.DebianDistribution(
82 os
.path
.join(dpkgdir
, 'status'))
83 host
._packagekit
= DummyPackageKit()
85 factory
= self
.make_factory(host
)
86 host
.get_package_info('gimp', factory
)
87 self
.assertEqual({}, self
.feed
.implementations
)
89 # Initially, we only get information about the installed version...
90 host
.get_package_info('python-bittorrent', factory
)
91 self
.assertEqual(1, len(self
.feed
.implementations
))
93 # Tell distro to fetch information about candidates...
94 master_feed
= parse_impls("""<package-implementation package='python-bittorrent'/>""")
96 candidates
= host
.fetch_candidates(master_feed
)
98 h
.wait_for_blocker(candidates
)
99 # Now we see the uninstalled package
100 self
.feed
= model
.ZeroInstallFeed(empty_feed
, local_path
= '/empty.xml')
101 host
.get_package_info('python-bittorrent', factory
)
102 self
.assertEqual(2, len(self
.feed
.implementations
))
104 self
.assertEqual(2, len(self
.feed
.implementations
))
105 bittorrent_installed
= self
.feed
.implementations
['package:deb:python-bittorrent:3.4.2-10:*']
106 bittorrent_uninstalled
= self
.feed
.implementations
['package:deb:python-bittorrent:3.4.2-11.1:*']
107 self
.assertEqual('3.4.2-10', bittorrent_installed
.get_version())
108 self
.assertTrue(bittorrent_installed
.installed
)
109 self
.assertFalse(bittorrent_uninstalled
.installed
)
110 self
.assertEqual(None, bittorrent_installed
.machine
)
112 self
.feed
= model
.ZeroInstallFeed(empty_feed
, local_path
= '/empty.xml')
113 host
.get_package_info('libxcomposite-dev', factory
)
114 self
.assertEqual(1, len(self
.feed
.implementations
))
115 libxcomposite
= self
.feed
.implementations
['package:deb:libxcomposite-dev:0.3.1-1:i386']
116 self
.assertEqual('0.3.1-1', libxcomposite
.get_version())
117 self
.assertEqual('i386', libxcomposite
.machine
)
120 rpmdir
= os
.path
.join(os
.path
.dirname(__file__
), 'rpm')
121 os
.environ
['PATH'] = rpmdir
+ ':' + self
.old_path
122 rpm
= distro
.RPMDistribution(os
.path
.join(rpmdir
, 'status'))
124 self
.assertEqual(2, len(rpm
.versions
))
126 factory
= self
.make_factory(rpm
)
127 rpm
.get_package_info('yast2-update', factory
)
128 self
.assertEqual(1, len(self
.feed
.implementations
))
129 yast
= self
.feed
.implementations
['package:rpm:yast2-update:2.15.23-21:i586']
130 self
.assertEqual('2.15.23-21', yast
.get_version())
131 self
.assertEqual('*-i586', yast
.arch
)
133 icache
= iface_cache
.IfaceCache(distro
= rpm
)
135 feed
= parse_impls("""
136 <package-implementation distributions="Debian" package="yast2-mail"/>
137 <package-implementation distributions="RPM" package="yast2-update"/>
139 icache
._feeds
[feed
.url
] = feed
140 distro_feed_url
= feed
.get_distro_feed()
141 impls
= icache
.get_feed(distro_feed_url
).implementations
142 self
.assertEqual("distribution:myfeed.xml", distro_feed_url
)
143 assert len(impls
) == 1, impls
145 assert impl
== 'package:rpm:yast2-update:2.15.23-21:i586'
147 feed
= parse_impls("""
148 <package-implementation distributions="RPM" package="yast2-mail"/>
149 <package-implementation distributions="RPM" package="yast2-update"/>
151 icache
._feeds
[feed
.url
] = feed
152 del icache
._feeds
['distribution:' + feed
.url
]
153 impls
= icache
.get_feed(feed
.get_distro_feed()).implementations
154 assert len(impls
) == 2, impls
156 feed
= parse_impls("""
157 <package-implementation distributions="" package="yast2-mail"/>
158 <package-implementation package="yast2-update"/>
160 icache
._feeds
[feed
.url
] = feed
161 del icache
._feeds
['distribution:' + feed
.url
]
162 impls
= icache
.get_feed(feed
.get_distro_feed()).implementations
163 assert len(impls
) == 2, impls
166 slackdir
= os
.path
.join(os
.path
.dirname(__file__
), 'slack')
167 slack
= distro
.SlackDistribution(os
.path
.join(slackdir
, 'packages'))
169 factory
= self
.make_factory(slack
)
170 slack
.get_package_info('gimp', factory
)
171 self
.assertEqual({}, self
.feed
.implementations
)
173 slack
.get_package_info('infozip', factory
)
174 self
.assertEqual(1, len(self
.feed
.implementations
))
175 zip = self
.feed
.implementations
['package:slack:infozip:5.52-2:i486']
176 self
.assertEqual('5.52-2', zip.get_version())
177 self
.assertEqual('i486', zip.machine
)
180 archdir
= os
.path
.join(os
.path
.dirname(__file__
), 'arch')
181 arch
= distro
.ArchDistribution(archdir
)
183 factory
= self
.make_factory(arch
)
184 arch
.get_package_info('gimp', factory
)
185 self
.assertEqual({}, self
.feed
.implementations
)
187 arch
.get_package_info('zeroinstall-injector', factory
)
188 self
.assertEqual(1, len(self
.feed
.implementations
))
189 zip = self
.feed
.implementations
['package:arch:zeroinstall-injector:1.5-1:*']
190 self
.assertEqual('1.5-1', zip.get_version())
192 def testGentoo(self
):
193 pkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'gentoo')
194 ebuilds
= distro
.GentooDistribution(pkgdir
)
196 factory
= self
.make_factory(ebuilds
)
197 ebuilds
.get_package_info('media-gfx/gimp', factory
)
198 self
.assertEqual({}, self
.feed
.implementations
)
200 ebuilds
.get_package_info('sys-apps/portage', factory
)
201 self
.assertEqual(1, len(self
.feed
.implementations
))
202 impl
= self
.feed
.implementations
['package:gentoo:sys-apps/portage:2.1.7.16:x86_64']
203 self
.assertEqual('2.1.7.16', impl
.get_version())
204 self
.assertEqual('x86_64', impl
.machine
)
206 ebuilds
.get_package_info('sys-kernel/gentoo-sources', factory
)
207 self
.assertEqual(3, len(self
.feed
.implementations
))
208 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.30-4:i686']
209 self
.assertEqual('2.6.30-4', impl
.get_version())
210 self
.assertEqual('i686', impl
.machine
)
211 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.32:x86_64']
212 self
.assertEqual('2.6.32', impl
.get_version())
213 self
.assertEqual('x86_64', impl
.machine
)
215 ebuilds
.get_package_info('app-emulation/emul-linux-x86-baselibs', factory
)
216 self
.assertEqual(4, len(self
.feed
.implementations
))
217 impl
= self
.feed
.implementations
['package:gentoo:app-emulation/emul-linux-x86-baselibs:20100220:i386']
218 self
.assertEqual('20100220', impl
.get_version())
219 self
.assertEqual('i386', impl
.machine
)
222 pkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'ports')
223 ports
= distro
.PortsDistribution(pkgdir
)
225 factory
= self
.make_factory(ports
)
226 ports
.get_package_info('zeroinstall-injector', factory
)
227 self
.assertEqual(1, len(self
.feed
.implementations
))
228 impl
= self
.feed
.implementations
['package:ports:zeroinstall-injector:0.41-2:' + distro
.host_machine
]
229 self
.assertEqual('0.41-2', impl
.get_version())
230 self
.assertEqual(distro
.host_machine
, impl
.machine
)
232 def testMacPorts(self
):
233 pkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'macports')
234 os
.environ
['PATH'] = pkgdir
+ ':' + self
.old_path
235 ports
= distro
.MacPortsDistribution(os
.path
.join(pkgdir
, 'registry.db'))
237 factory
= self
.make_factory(ports
)
238 ports
.get_package_info('zeroinstall-injector', factory
)
239 self
.assertEqual(1, len(self
.feed
.implementations
))
240 impl
= self
.feed
.implementations
['package:macports:zeroinstall-injector:1.0-0:*']
241 self
.assertEqual('1.0-0', impl
.get_version())
242 self
.assertEqual(None, impl
.machine
)
244 def testCleanVersion(self
):
245 self
.assertEqual('0.3.1-1', distro
.try_cleanup_distro_version('1:0.3.1-1'))
246 self
.assertEqual('0.3.1-1', distro
.try_cleanup_distro_version('0.3.1-1ubuntu0'))
247 self
.assertEqual('0.3-post1-rc2', distro
.try_cleanup_distro_version('0.3-post1-rc2'))
248 self
.assertEqual('0.3.1-2', distro
.try_cleanup_distro_version('0.3.1-r2-r3'))
250 def testCommand(self
):
251 dpkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'dpkg')
252 host
= distro
.DebianDistribution(
253 os
.path
.join(dpkgdir
, 'status'))
254 host
._packagekit
= DummyPackageKit()
256 factory
= self
.make_factory(host
)
258 master_feed
= parse_impls("""<package-implementation main='/unused' package='python-bittorrent'><command path='/bin/sh' name='run'/></package-implementation>""")
259 icache
= iface_cache
.IfaceCache(distro
= host
)
260 icache
._feeds
[master_feed
.url
] = master_feed
261 #del icache._feeds['distribution:' + master_feed.url]
262 impl
, = icache
.get_feed(master_feed
.get_distro_feed()).implementations
.values()
263 self
.assertEqual('/bin/sh', impl
.main
)
265 if __name__
== '__main__':