2 from basetest
import BaseTest
, empty_feed
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
.assertEquals(None, cache
.get("foo"))
35 self
.assertEquals("1", cache
.get("foo"))
37 self
.assertEquals("2", cache
.get("foo"))
40 cache
= distro
.Cache('test-cache', src
.name
, 1)
41 self
.assertEquals("2", cache
.get("foo"))
46 self
.assertEquals(None, cache
.get("foo"))
49 # new cache... (format change)
50 cache
= distro
.Cache('test-cache', src
.name
, 2)
51 self
.assertEquals(None, cache
.get("foo"))
56 def make_factory(self
, distro
):
58 impl
= model
.DistributionImplementation(self
.feed
, id, distro
)
59 assert id not in self
.feed
.implementations
60 self
.feed
.implementations
[id] = impl
64 def testDefault(self
):
65 host
= distro
.Distribution()
67 factory
= self
.make_factory(host
)
68 host
.get_package_info('gimp', factory
)
69 self
.assertEquals(self
.feed
.implementations
, {})
72 dpkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'dpkg')
73 host
= distro
.DebianDistribution(
74 os
.path
.join(dpkgdir
, 'status'),
75 os
.path
.join(dpkgdir
, 'pkgcache.bin'))
77 factory
= self
.make_factory(host
)
78 host
.get_package_info('gimp', factory
)
79 self
.assertEquals({}, self
.feed
.implementations
)
81 # Initially, we only get information about the installed version...
82 host
.get_package_info('python-bittorrent', factory
)
83 self
.assertEquals(1, len(self
.feed
.implementations
))
85 # Tell distro to fetch information about candidates...
86 master_feed
= parse_impls("""<package-implementation package='python-bittorrent'/>""")
88 candidates
= host
.fetch_candidates(master_feed
)
90 h
.wait_for_blocker(candidates
)
91 # Now we see the uninstalled package
92 self
.feed
= model
.ZeroInstallFeed(empty_feed
, local_path
= '/empty.xml')
93 host
.get_package_info('python-bittorrent', factory
)
94 self
.assertEquals(2, len(self
.feed
.implementations
))
96 self
.assertEquals(2, len(self
.feed
.implementations
))
97 bittorrent_installed
= self
.feed
.implementations
['package:deb:python-bittorrent:3.4.2-10']
98 bittorrent_uninstalled
= self
.feed
.implementations
['package:deb:python-bittorrent:3.4.2-11.1']
99 self
.assertEquals('3.4.2-10', bittorrent_installed
.get_version())
100 self
.assertTrue(bittorrent_installed
.installed
)
101 self
.assertFalse(bittorrent_uninstalled
.installed
)
102 self
.assertEquals(None, bittorrent_installed
.machine
)
104 self
.feed
= model
.ZeroInstallFeed(empty_feed
, local_path
= '/empty.xml')
105 host
.get_package_info('libxcomposite-dev', factory
)
106 self
.assertEquals(1, len(self
.feed
.implementations
))
107 libxcomposite
= self
.feed
.implementations
['package:deb:libxcomposite-dev:0.3.1-1']
108 self
.assertEquals('0.3.1-1', libxcomposite
.get_version())
109 self
.assertEquals('i386', libxcomposite
.machine
)
112 rpmdir
= os
.path
.join(os
.path
.dirname(__file__
), 'rpm')
113 os
.environ
['PATH'] = rpmdir
+ ':' + self
.old_path
114 rpm
= distro
.RPMDistribution(os
.path
.join(rpmdir
, 'status'))
116 self
.assertEquals(2, len(rpm
.versions
))
118 factory
= self
.make_factory(rpm
)
119 rpm
.get_package_info('yast2-update', factory
)
120 self
.assertEquals(1, len(self
.feed
.implementations
))
121 yast
= self
.feed
.implementations
['package:rpm:yast2-update:2.15.23-21:i586']
122 self
.assertEquals('2.15.23-21', yast
.get_version())
123 self
.assertEquals('*-i586', yast
.arch
)
125 icache
= iface_cache
.IfaceCache(distro
= rpm
)
127 feed
= parse_impls("""
128 <package-implementation distributions="Debian" package="yast2-mail"/>
129 <package-implementation distributions="RPM" package="yast2-update"/>
131 icache
._feeds
[feed
.url
] = feed
132 distro_feed_url
= feed
.get_distro_feed()
133 impls
= icache
.get_feed(distro_feed_url
).implementations
134 self
.assertEquals("distribution:myfeed.xml", distro_feed_url
)
135 assert len(impls
) == 1, impls
137 assert impl
== 'package:rpm:yast2-update:2.15.23-21:i586'
139 feed
= parse_impls("""
140 <package-implementation distributions="RPM" package="yast2-mail"/>
141 <package-implementation distributions="RPM" package="yast2-update"/>
143 icache
._feeds
[feed
.url
] = feed
144 del icache
._feeds
['distribution:' + feed
.url
]
145 impls
= icache
.get_feed(feed
.get_distro_feed()).implementations
146 assert len(impls
) == 2, impls
148 feed
= parse_impls("""
149 <package-implementation distributions="" package="yast2-mail"/>
150 <package-implementation package="yast2-update"/>
152 icache
._feeds
[feed
.url
] = feed
153 del icache
._feeds
['distribution:' + feed
.url
]
154 impls
= icache
.get_feed(feed
.get_distro_feed()).implementations
155 assert len(impls
) == 2, impls
158 slackdir
= os
.path
.join(os
.path
.dirname(__file__
), 'slack')
159 slack
= distro
.SlackDistribution(os
.path
.join(slackdir
, 'packages'))
161 factory
= self
.make_factory(slack
)
162 slack
.get_package_info('gimp', factory
)
163 self
.assertEquals({}, self
.feed
.implementations
)
165 slack
.get_package_info('infozip', factory
)
166 self
.assertEquals(1, len(self
.feed
.implementations
))
167 zip = self
.feed
.implementations
['package:slack:infozip:5.52-2:i486']
168 self
.assertEquals('5.52-2', zip.get_version())
169 self
.assertEquals('i486', zip.machine
)
171 def testGentoo(self
):
172 pkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'gentoo')
173 ebuilds
= distro
.GentooDistribution(pkgdir
)
175 factory
= self
.make_factory(ebuilds
)
176 ebuilds
.get_package_info('media-gfx/gimp', factory
)
177 self
.assertEquals({}, self
.feed
.implementations
)
179 ebuilds
.get_package_info('sys-apps/portage', factory
)
180 self
.assertEquals(1, len(self
.feed
.implementations
))
181 impl
= self
.feed
.implementations
['package:gentoo:sys-apps/portage:2.1.7.16:x86_64']
182 self
.assertEquals('2.1.7.16', impl
.get_version())
183 self
.assertEquals('x86_64', impl
.machine
)
185 ebuilds
.get_package_info('sys-kernel/gentoo-sources', factory
)
186 self
.assertEquals(3, len(self
.feed
.implementations
))
187 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.30-4:i686']
188 self
.assertEquals('2.6.30-4', impl
.get_version())
189 self
.assertEquals('i686', impl
.machine
)
190 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.32:x86_64']
191 self
.assertEquals('2.6.32', impl
.get_version())
192 self
.assertEquals('x86_64', impl
.machine
)
194 ebuilds
.get_package_info('app-emulation/emul-linux-x86-baselibs', factory
)
195 self
.assertEquals(4, len(self
.feed
.implementations
))
196 impl
= self
.feed
.implementations
['package:gentoo:app-emulation/emul-linux-x86-baselibs:20100220:i386']
197 self
.assertEquals('20100220', impl
.get_version())
198 self
.assertEquals('i386', impl
.machine
)
201 pkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'ports')
202 ports
= distro
.PortsDistribution(pkgdir
)
204 factory
= self
.make_factory(ports
)
205 ports
.get_package_info('zeroinstall-injector', factory
)
206 self
.assertEquals(1, len(self
.feed
.implementations
))
207 impl
= self
.feed
.implementations
['package:ports:zeroinstall-injector:0.41:x86_64']
208 self
.assertEquals('0.41', impl
.get_version())
209 self
.assertEquals('x86_64', impl
.machine
)
211 def testCleanVersion(self
):
212 self
.assertEquals('0.3.1-1', distro
.try_cleanup_distro_version('1:0.3.1-1'))
213 self
.assertEquals('0.3.1-1', distro
.try_cleanup_distro_version('0.3.1-1ubuntu0'))
214 self
.assertEquals('0.3-post1-rc2', distro
.try_cleanup_distro_version('0.3-post1-rc2'))
215 self
.assertEquals('0.3.1-2', distro
.try_cleanup_distro_version('0.3.1-r2-r3'))
217 if __name__
== '__main__':