msm: consistency for equally ranked keys
[platform/upstream/rpm.git] / tests / rpmpython.at
1 #    rpmpython.at: test rpm python bindings
2 #    TODO: conditionalize on python availability
3
4 AT_BANNER([Python bindings])
5
6 RPMPY_TEST([module import],[
7 myprint(rpm.__version__)
8 ],
9 [AT_PACKAGE_VERSION]
10 )
11
12 RPMPY_TEST([macro manipulation],[
13 def prexp(m):
14     myprint(rpm.expandMacro('%%{?%s}' % m))
15
16 mname = '__no_such_macro_yet'
17 prexp(mname)
18 rpm.addMacro(mname, '/bin/sh')
19 prexp(mname)
20 rpm.addMacro(mname, '/bin/false')
21 prexp(mname)
22 rpm.delMacro(mname)
23 prexp(mname)
24 rpm.delMacro(mname)
25 prexp(mname)
26 ],
27 [
28 /bin/sh
29 /bin/false
30 /bin/sh
31
32 ],
33 [])
34
35 RPMPY_TEST([basic rpmio],[
36 msg = 'Killroy was here\n'
37 data = msg * 10
38 # TODO: test other compression types too if built in
39 for iot in [ 'fpio', 'fdio', 'ufdio', 'gzdio' ]:
40     fn = 'pyio.%s' % iot
41     fd = rpm.fd(fn, 'w', iot)
42     pos = fd.tell()
43     if pos != -2 and pos != 0:
44         myprint('bad start pos %d' % fd.tell())
45     if fd.write(data) != len(data):
46         myprint('%s write fail' % iot)
47     if fn != fd.name:
48         myprint('bad file name %s' % fd.name)
49     fd.flush()
50     pos = fd.tell()
51     if pos != -2 and pos != len(data):
52         myprint('bad end pos %d' % fd.tell())
53     fd = rpm.fd(fn, 'r', iot)
54     rdata = fd.read()
55     if rdata != data:
56         myprint('%s read fail (got %d bytes)' % (iot, len(rdata), rdata))
57     # compressed io types cant seek
58     if iot == 'ufdio':
59         fd.seek(0)
60     else:
61         fd = rpm.fd(fn, 'r', iot)
62     if fn != fd.name:
63         myprint('bad file name %s' % fd.name)
64     rdata = fd.read(len(msg))
65     if rdata != msg:
66         myprint('%s sized read fail (got %d bytes)\n%s' % (iot, len(rdata), rdata))
67 ],
68 [])
69
70 RPMPY_TEST([spec parse],[
71 # TODO: add a better test spec with sub-packages etc
72 spec = rpm.spec('${RPMDATA}/SPECS/hello.spec')
73 for (name, num, flags) in spec.sources:
74     myprint('src %s %d %d' % (name, num, flags))
75 for pkg in spec.packages:
76     myprint(pkg.header.format('%{nvr}'))
77 myprint(spec.sourceHeader.format('%{nvr}'))
78 ],
79 [src hello-1.0-modernize.patch 0 2
80 src hello-1.0.tar.gz 0 1
81 hello-1.0-1
82 hello-1.0-1
83 ])
84
85 RPMPY_TEST([basic header manipulation],[
86 h = rpm.hdr()
87 h['name'] = 'testpkg'
88 h['version'] = '1.0'
89 h['release'] = '1'
90 h['epoch'] = 5
91 h['arch'] = 'noarch'
92 myprint(h['nevra'])
93 del h['epoch']
94 myprint(h['nevra'])
95 for a in ['name', 'bugurl', '__class__', '__foo__', ]:
96     try:
97         x = getattr(h, a)
98         myprint(x)
99     except AttributeError, exc:
100         myprint(exc)
101 ],
102 [testpkg-5:1.0-1.noarch
103 testpkg-1.0-1.noarch
104 testpkg
105 None
106 <type 'rpm.hdr'>
107 'rpm.hdr' object has no attribute '__foo__']
108 )
109
110 RPMPY_TEST([invalid header data],[
111 h1 = rpm.hdr()
112 h1['basenames'] = ['bing', 'bang', 'bong']
113 h1['dirnames'] = ['/opt/', '/flopt/']
114 h1['dirindexes'] = [ 1, 0, 3 ]
115 h2 = rpm.hdr()
116 h2['basenames'] = ['bing', 'bang', 'bong']
117 h2['dirnames'] = ['/opt/', '/flopt/']
118 h2['dirindexes'] = [ 0, 0, 1 ]
119 for h in [h1, h2]:
120     try:
121         myprint(','.join(h['filenames']))
122     except rpm.error, exc:
123         myprint(exc)
124 ],
125 [invalid header data
126 /opt/bing,/opt/bang,/flopt/bong]
127 )
128
129 RPMPY_TEST([reading a package file],[
130 ts = rpm.ts()
131 h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-1.0-1.ppc64.rpm')
132 myprint(h['arch'])
133 ],
134 [ppc64]
135 )
136
137 RPMPY_TEST([add package to transaction],[
138 ts = rpm.ts()
139 ts.addInstall('${RPMDATA}/RPMS/foo-1.0-1.noarch.rpm', 'u')
140 for e in ts:
141     myprint(e.NEVRA())
142 ts.clear()
143 for e in ts:
144     myprint(e.NEVRA())
145 ],
146 [foo-1.0-1.noarch]
147 )
148
149 RPMPY_TEST([add bogus package to transaction 1],[
150 ts = rpm.ts()
151 h = rpm.hdr()
152 h['name'] = "foo"
153 try:
154     ts.addInstall(h, 'foo', 'u')
155 except rpm.error, err:
156     myprint(err)
157 for e in ts:
158     myprint(e.NEVRA())
159 ],
160 [adding package to transaction failed]
161 )
162
163 RPMPY_TEST([add bogus package to transaction 2],[
164 ts = rpm.ts()
165 h = rpm.hdr()
166 h['name'] = 'foo'
167 h['version'] = '1.0'
168 h['release'] = '1'
169 h['os'] = 'linux'
170 h['arch'] = 'noarch'
171 h['basenames'] = ['bing', 'bang', 'bong']
172 h['dirnames'] = ['/opt' '/flopt']
173 h['dirindexes'] = [ 1, 2, 3 ]
174 try:
175     ts.addInstall(h, 'foo', 'u')
176 except rpm.error, err:
177     myprint(err)
178 for e in ts:
179     myprint(e.NEVRA())
180 ],
181 [adding package to transaction failed]
182 )
183
184 AT_SETUP([database iterators])
185 AT_KEYWORDS([python rpmdb])
186 AT_CHECK([
187 RPMDB_CLEAR
188 RPMDB_INIT
189 runroot rpm -i \
190   --justdb --nodeps --ignorearch --ignoreos \
191   /data/RPMS/foo-1.0-1.noarch.rpm \
192   /data/RPMS/hello-2.0-1.i686.rpm
193 ],
194 [0],
195 [],
196 [])
197
198 RPMPY_CHECK([
199 ts = rpm.ts()
200 for h in ts.dbMatch('name'):
201     myprint(h['nevra'])
202 ],
203 [foo-1.0-1.noarch
204 hello-2.0-1.i686
205 ],
206 [])
207
208 RPMPY_CHECK([
209 ts = rpm.ts()
210 for h in ts.dbMatch('obsoletes'):
211     myprint(h['nevra'])
212 ],
213 [foo-1.0-1.noarch
214 ],
215 [])
216
217 RPMPY_CHECK([
218 ts = rpm.ts()
219 for h in ts.dbMatch('provides', 'hi'):
220     myprint(h['nevra'])
221 ],
222 [foo-1.0-1.noarch
223 ],
224 [])
225
226 RPMPY_CHECK([
227 ts = rpm.ts()
228 for h in ts.dbMatch('basenames', '/usr/share/doc/hello-2.0/FAQ'):
229     myprint(h['nevra'])
230 ],
231 [hello-2.0-1.i686
232 ],
233 [])
234 RPMPY_CHECK([
235 ts = rpm.ts()
236 for di in ts.dbIndex('obsoletes'):
237     myprint(di)
238 ],
239 [howdy
240 ],
241 [])
242
243 RPMPY_CHECK([
244 ts = rpm.ts()
245 for di in ts.dbIndex('provides'):
246     myprint(di)
247 ],
248 [foo
249 hello
250 hello(x86-32)
251 hi
252 ],
253 [])
254 AT_CLEANUP
255
256 RPMPY_TEST([dependency sets 1],[
257 ts = rpm.ts()
258 h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-1.0-1.ppc64.rpm')
259 for dep in rpm.ds(h, 'requires'):
260     myprint(dep.DNEVR())
261 ],
262 [R /bin/sh
263 R /bin/sh
264 R /bin/sh
265 R /bin/sh
266 R libc.so.6
267 R libc.so.6(GLIBC_2.0)
268 R rpmlib(CompressedFileNames) <= 3.0.4-1
269 R rpmlib(PayloadFilesHavePrefix) <= 4.0-1
270 R rtld(GNU_HASH)]
271 )
272
273 RPMPY_TEST([dependency sets 2],[
274 ts = rpm.ts()
275 h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-2.0-1.i686.rpm')
276 ds = rpm.ds(h, 'provides')
277 myprint('%d %d' % (ds.Instance(), ds.Count()))
278 ],
279 [0 2
280 ],
281 [])
282
283 RPMPY_TEST([file info sets 1],[
284 ts = rpm.ts()
285 h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-2.0-1.i686.rpm')
286 fi = rpm.fi(h)
287 myprint(fi.FC())
288 for f in fi:
289    myprint('%x: %s' % (fi.FFlags(), fi.FN()))
290 ],
291 [5
292 0: /usr/bin/hello
293 0: /usr/share/doc/hello-2.0
294 2: /usr/share/doc/hello-2.0/COPYING
295 2: /usr/share/doc/hello-2.0/FAQ
296 2: /usr/share/doc/hello-2.0/README
297 ],
298 [])
299