1 #!/usr/bin/env python2.5
2 from basetest
import BaseTest
, empty_feed
6 sys
.path
.insert(0, '..')
7 from zeroinstall
.injector
import distro
, model
9 class TestDistro(BaseTest
):
12 self
.feed
= model
.ZeroInstallFeed(empty_feed
, local_path
= '/empty.xml')
15 BaseTest
.tearDown(self
)
17 def factory(self
, id):
18 return self
.feed
._get
_impl
(id)
20 def testDefault(self
):
21 host
= distro
.Distribution()
23 host
.get_package_info('gimp', self
.factory
)
24 self
.assertEquals(self
.feed
.implementations
, {})
27 dpkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'dpkg')
28 host
= distro
.DebianDistribution(os
.path
.join(dpkgdir
, 'status'))
30 self
.assertEquals(2, len(host
.versions
))
32 host
.get_package_info('gimp', self
.factory
)
33 self
.assertEquals({}, self
.feed
.implementations
)
35 host
.get_package_info('python-bittorrent', self
.factory
)
36 self
.assertEquals(1, len(self
.feed
.implementations
))
37 bittorrent
= self
.feed
.implementations
['package:deb:python-bittorrent:3.4.2-10']
38 self
.assertEquals('3.4.2-10', bittorrent
.get_version())
40 host
.get_package_info('libxcomposite-dev', self
.factory
)
41 self
.assertEquals(2, len(self
.feed
.implementations
))
42 libxcomposite
= self
.feed
.implementations
['package:deb:libxcomposite-dev:0.3.1-1']
43 self
.assertEquals('0.3.1-1', libxcomposite
.get_version())
46 rpmdir
= os
.path
.join(os
.path
.dirname(__file__
), 'rpm')
47 os
.environ
['PATH'] = rpmdir
+ ':' + self
.old_path
48 rpm
= distro
.RPMDistribution(os
.path
.join(rpmdir
, 'status'))
50 self
.assertEquals(2, len(rpm
.versions
))
52 rpm
.get_package_info('yast2-update', self
.factory
)
53 self
.assertEquals(1, len(self
.feed
.implementations
))
54 yast
= self
.feed
.implementations
['package:rpm:yast2-update:2.15.23-21:i586']
55 self
.assertEquals('2.15.23-21', yast
.get_version())
56 self
.assertEquals('*-i586', yast
.arch
)
59 pkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'gentoo')
60 ebuilds
= distro
.GentooDistribution(pkgdir
)
62 ebuilds
.get_package_info('gimp', self
.factory
)
63 self
.assertEquals({}, self
.feed
.implementations
)
65 ebuilds
.get_package_info('sys-apps/portage', self
.factory
)
66 self
.assertEquals(1, len(self
.feed
.implementations
))
67 impl
= self
.feed
.implementations
['package:gentoo:sys-apps/portage:2.1.7.16:x86_64']
68 self
.assertEquals('2.1.7.16', impl
.get_version())
70 ebuilds
.get_package_info('sys-kernel/gentoo-sources', self
.factory
)
71 self
.assertEquals(3, len(self
.feed
.implementations
))
72 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.30-4:i686']
73 self
.assertEquals('2.6.30-4', impl
.get_version())
74 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.32:x86_64']
75 self
.assertEquals('2.6.32', impl
.get_version())
77 def testCleanVersion(self
):
78 self
.assertEquals('1', distro
.try_cleanup_distro_version('1:0.3.1-1'))
79 self
.assertEquals('0.3.1-1', distro
.try_cleanup_distro_version('0.3.1-1ubuntu0'))
80 self
.assertEquals('0.3-post1-rc2', distro
.try_cleanup_distro_version('0.3-post1-rc2'))
81 self
.assertEquals('0.3.1-2', distro
.try_cleanup_distro_version('0.3.1-r2-r3'))
83 suite
= unittest
.makeSuite(TestDistro
)
84 if __name__
== '__main__':