Add beginnings of python bindings test-suite
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 9 Dec 2010 14:32:56 +0000 (16:32 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 9 Dec 2010 14:32:56 +0000 (16:32 +0200)
- Add some basic infrastructure: point PYTHONPATH to the testing
  directory, helper macros to allow use of in-line python in test-suite
- Throw in a couple of simple tests for starters

tests/Makefile.am
tests/atlocal.in
tests/rpmpython.at [new file with mode: 0644]
tests/rpmtests.at

index 97644c7..cb24562 100644 (file)
@@ -25,6 +25,7 @@ TESTSUITE_AT += rpmdeps.at
 TESTSUITE_AT += rpmconflict.at
 TESTSUITE_AT += rpmconfig.at
 TESTSUITE_AT += rpmmacro.at
+TESTSUITE_AT += rpmpython.at
 EXTRA_DIST += $(TESTSUITE_AT)
 
 ## testsuite data
index 011f9be..d0ea0c8 100644 (file)
@@ -3,6 +3,10 @@ export LD_LIBRARY_PATH
 PATH="${abs_builddir}/testing@rpmbindir@:${abs_builddir}/testing@usrbindir@:$PATH"
 export PATH
 
+PYLIBDIR=`python -c "from distutils.sysconfig import get_python_lib; import sys; sys.stdout.write(get_python_lib(1))"`
+PYTHONPATH="${abs_builddir}/testing${PYLIBDIR}"
+export PYTHONPATH
+
 RPMTEST="${abs_builddir}/testing"
 RPMDATA="${abs_srcdir}/data/"
 
diff --git a/tests/rpmpython.at b/tests/rpmpython.at
new file mode 100644 (file)
index 0000000..8651ca5
--- /dev/null
@@ -0,0 +1,59 @@
+#    rpmpython.at: test rpm python bindings
+#    TODO: conditionalize on python availability
+
+AT_BANNER([Python bindings])
+
+m4_define([RUNPY],[
+cat << EOF > test.py
+import rpm, sys
+def myprint(msg):
+    sys.stdout.write('%s\n' % msg)
+$1
+EOF
+python test.py
+])
+
+m4_define([PY_CHECK],[
+AT_SETUP([$1])
+AT_KEYWORDS([python])
+AT_CHECK([RUNPY([[$2]])], [], [$3], [$4])
+AT_CLEANUP
+])
+
+PY_CHECK([module import],[
+myprint(rpm.__version__)
+],
+[AT_PACKAGE_VERSION]
+)
+
+PY_CHECK([basic header manipulation],[
+h = rpm.hdr()
+h['name'] = 'testpkg'
+h['version'] = '1.0'
+h['release'] = '1'
+h['epoch'] = 5
+h['arch'] = 'noarch'
+myprint(h['nevra'])
+del h['epoch']
+myprint(h['nevra'])
+],
+[testpkg-5:1.0-1.noarch
+testpkg-1.0-1.noarch]
+)
+
+PY_CHECK([reading a package file],[
+ts = rpm.ts()
+h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-1.0-1.ppc64.rpm')
+myprint(h['arch'])
+],
+[ppc64]
+)
+
+PY_CHECK([add package to transaction],[
+ts = rpm.ts()
+ts.addInstall('${RPMDATA}/RPMS/foo-1.0-1.noarch.rpm', 'u')
+for e in ts:
+    myprint(e.NEVRA())
+],
+[foo-1.0-1.noarch]
+)
index 315318f..be0bdb0 100644 (file)
@@ -9,3 +9,4 @@ m4_include([rpmdeps.at])
 m4_include([rpmconflict.at])
 m4_include([rpmconfig.at])
 m4_include([rpmmacro.at])
+m4_include([rpmpython.at])