From 2a37d9a4dcfd172db9a63584ec2267702153e00b Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 9 Dec 2010 16:32:56 +0200 Subject: [PATCH] Add beginnings of python bindings test-suite - 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 | 1 + tests/atlocal.in | 4 ++++ tests/rpmpython.at | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/rpmtests.at | 1 + 4 files changed, 65 insertions(+) create mode 100644 tests/rpmpython.at diff --git a/tests/Makefile.am b/tests/Makefile.am index 97644c7..cb24562 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/atlocal.in b/tests/atlocal.in index 011f9be..d0ea0c8 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -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 index 0000000..8651ca5 --- /dev/null +++ b/tests/rpmpython.at @@ -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] +) diff --git a/tests/rpmtests.at b/tests/rpmtests.at index 315318f..be0bdb0 100644 --- a/tests/rpmtests.at +++ b/tests/rpmtests.at @@ -9,3 +9,4 @@ m4_include([rpmdeps.at]) m4_include([rpmconflict.at]) m4_include([rpmconfig.at]) m4_include([rpmmacro.at]) +m4_include([rpmpython.at]) -- 2.7.4