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
10 def parse_impls(impls
, test_distro
):
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", test_distro
)
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
)
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
)
41 self
.assertEquals("2", cache
.get("foo"))
46 self
.assertEquals("2", cache
.get("foo"))
49 cache
= distro
.Cache('test-cache', src
.name
)
50 self
.assertEquals(None, cache
.get("foo"))
55 def factory(self
, id):
56 impl
= model
.DistributionImplementation(self
.feed
, id)
57 assert id not in self
.feed
.implementations
58 self
.feed
.implementations
[id] = impl
61 def testDefault(self
):
62 host
= distro
.Distribution()
64 host
.get_package_info('gimp', self
.factory
)
65 self
.assertEquals(self
.feed
.implementations
, {})
68 dpkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'dpkg')
69 host
= distro
.DebianDistribution(os
.path
.join(dpkgdir
, 'status'))
71 self
.assertEquals(2, len(host
.versions
))
73 host
.get_package_info('gimp', self
.factory
)
74 self
.assertEquals({}, self
.feed
.implementations
)
76 host
.get_package_info('python-bittorrent', self
.factory
)
77 self
.assertEquals(1, len(self
.feed
.implementations
))
78 bittorrent
= self
.feed
.implementations
['package:deb:python-bittorrent:3.4.2-10']
79 self
.assertEquals('3.4.2-10', bittorrent
.get_version())
81 host
.get_package_info('libxcomposite-dev', self
.factory
)
82 self
.assertEquals(2, len(self
.feed
.implementations
))
83 libxcomposite
= self
.feed
.implementations
['package:deb:libxcomposite-dev:0.3.1-1']
84 self
.assertEquals('0.3.1-1', libxcomposite
.get_version())
87 rpmdir
= os
.path
.join(os
.path
.dirname(__file__
), 'rpm')
88 os
.environ
['PATH'] = rpmdir
+ ':' + self
.old_path
89 rpm
= distro
.RPMDistribution(os
.path
.join(rpmdir
, 'status'))
91 self
.assertEquals(2, len(rpm
.versions
))
93 rpm
.get_package_info('yast2-update', self
.factory
)
94 self
.assertEquals(1, len(self
.feed
.implementations
))
95 yast
= self
.feed
.implementations
['package:rpm:yast2-update:2.15.23-21:i586']
96 self
.assertEquals('2.15.23-21', yast
.get_version())
97 self
.assertEquals('*-i586', yast
.arch
)
99 impls
= parse_impls("""
100 <package-implementation distributions="Debian" package="yast2-mail"/>
101 <package-implementation distributions="RPM" package="yast2-update"/>
102 """, rpm
).implementations
103 assert len(impls
) == 1, impls
105 assert impl
== 'package:rpm:yast2-update:2.15.23-21:i586'
107 impls
= parse_impls("""
108 <package-implementation distributions="RPM" package="yast2-mail"/>
109 <package-implementation distributions="RPM" package="yast2-update"/>
110 """, rpm
).implementations
111 assert len(impls
) == 2, impls
113 impls
= parse_impls("""
114 <package-implementation distributions="" package="yast2-mail"/>
115 <package-implementation package="yast2-update"/>
116 """, rpm
).implementations
117 assert len(impls
) == 2, impls
119 def testGentoo(self
):
120 pkgdir
= os
.path
.join(os
.path
.dirname(__file__
), 'gentoo')
121 ebuilds
= distro
.GentooDistribution(pkgdir
)
123 ebuilds
.get_package_info('media-gfx/gimp', self
.factory
)
124 self
.assertEquals({}, self
.feed
.implementations
)
126 ebuilds
.get_package_info('sys-apps/portage', self
.factory
)
127 self
.assertEquals(1, len(self
.feed
.implementations
))
128 impl
= self
.feed
.implementations
['package:gentoo:sys-apps/portage:2.1.7.16:x86_64']
129 self
.assertEquals('2.1.7.16', impl
.get_version())
131 ebuilds
.get_package_info('sys-kernel/gentoo-sources', self
.factory
)
132 self
.assertEquals(3, len(self
.feed
.implementations
))
133 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.30-4:i686']
134 self
.assertEquals('2.6.30-4', impl
.get_version())
135 impl
= self
.feed
.implementations
['package:gentoo:sys-kernel/gentoo-sources:2.6.32:x86_64']
136 self
.assertEquals('2.6.32', impl
.get_version())
138 def testCleanVersion(self
):
139 self
.assertEquals('1', distro
.try_cleanup_distro_version('1:0.3.1-1'))
140 self
.assertEquals('0.3.1-1', distro
.try_cleanup_distro_version('0.3.1-1ubuntu0'))
141 self
.assertEquals('0.3-post1-rc2', distro
.try_cleanup_distro_version('0.3-post1-rc2'))
142 self
.assertEquals('0.3.1-2', distro
.try_cleanup_distro_version('0.3.1-r2-r3'))
144 suite
= unittest
.makeSuite(TestDistro
)
145 if __name__
== '__main__':
146 sys
.argv
.append('-v')