1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-14 00:19:50 +02:00

tests: Run the tests for the Python bindings of GPGME.

* tests/gpgme/gpgme-defs.scm (create-file): Write lines.
(create-gpgmehome): Extend function to create the right environment
for the Python tests.
* tests/gpgme/run-tests.scm: Make an environment cache for the Python
tests and enable them.
* tests/gpgme/wrap.scm: Do not hardcode the path of the Python
interpreter.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2017-03-09 14:33:02 +01:00
parent cca91a3f8f
commit 046a15a88c
No known key found for this signature in database
GPG Key ID: DD1A52F9DA8C9020
3 changed files with 51 additions and 15 deletions

View File

@ -45,12 +45,25 @@
;; The tests expect the pinentry to return the passphrase "abc". ;; The tests expect the pinentry to return the passphrase "abc".
(setenv "PINENTRY_USER_DATA" "abc" #t) (setenv "PINENTRY_USER_DATA" "abc" #t)
(define (create-file name content) (define (create-file name . lines)
(letfd ((fd (open name (logior O_WRONLY O_CREAT O_BINARY) #o600))) (letfd ((fd (open name (logior O_WRONLY O_CREAT O_BINARY) #o600)))
(display content (fdopen fd "wb")))) (let ((port (fdopen fd "wb")))
(for-each (lambda (line) (display line port) (newline port)) lines))))
(define (create-gpgmehome . path) (define (create-gpgmehome . path)
(create-file "gpg.conf" "no-force-v3-sigs\n") ;; Support for various environments.
(define mode
(cond
((equal? path '("lang" "python" "tests"))
(set! path '("tests" "gpg")) ;; Mostly uses files from tests/gpg.
'python)
(else
'gpg)))
(create-file
"gpg.conf"
"no-force-v3-sigs"
(string-append "agent-program " (tool 'gpg-agent) "|--debug-quick-random\n"))
(create-file (create-file
"gpg-agent.conf" "gpg-agent.conf"
(string-append "pinentry-program " (tool 'pinentry))) (string-append "pinentry-program " (tool 'pinentry)))
@ -75,6 +88,21 @@
(call-check `(,@GPG --yes --import ,(apply in-gpgme-srcdir (call-check `(,@GPG --yes --import ,(apply in-gpgme-srcdir
`(,@path ,file))))) `(,@path ,file)))))
(list "pubdemo.asc" "secdemo.asc")) (list "pubdemo.asc" "secdemo.asc"))
(when (equal? mode 'python)
(log "Importing extra keys for Python tests")
(for-each
(lambda (file)
(call-check `(,@GPG --yes --import
,(apply in-gpgme-srcdir
`("lang" "python" "tests" ,file)))))
(list "encrypt-only.asc" "sign-only.asc"))
(log "Marking key as trusted")
(pipe:do
(pipe:echo "A0FF4590BB6122EDEF6E3C542D727CC768697734:6:\n")
(pipe:spawn `(,(tool 'gpg) --import-ownertrust))))
(stop-agent)) (stop-agent))
;; Initialize the test environment, install appropriate configuration ;; Initialize the test environment, install appropriate configuration

View File

@ -40,7 +40,11 @@
run-tests-parallel run-tests-parallel
run-tests-sequential)) run-tests-sequential))
(setup-c (make-environment-cache (setup-c (make-environment-cache
(test::scm #f "setup.scm" (in-srcdir "setup.scm") "--" "tests" "gpg"))) (test::scm #f "setup.scm (tests/gpg)" (in-srcdir "setup.scm")
"--" "tests" "gpg")))
(setup-py (make-environment-cache
(test::scm #f "setup.scm (lang/python/tests)" (in-srcdir "setup.scm")
"--" "lang" "python" "tests")))
(tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*))) (tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*)))
(runner (runner
(apply (apply
@ -67,6 +71,5 @@
-- ,@(:path cmpnts)))) -- ,@(:path cmpnts))))
(if (null? tests) (all-tests makefile (:key cmpnts)) tests)))) (if (null? tests) (all-tests makefile (:key cmpnts)) tests))))
`((("tests" "gpg") "c_tests" ,setup-c) `((("tests" "gpg") "c_tests" ,setup-c)
;; XXX: Not yet. (("lang" "python" "tests") "py_tests" ,setup-py)
;; (("lang" "python" "tests") "py_tests")
(("lang" "qt" "tests") "TESTS" ,setup-c)))))) (("lang" "qt" "tests") "TESTS" ,setup-c))))))

View File

@ -29,6 +29,9 @@
(setenv "top_srcdir" gpgme-srcdir #t) (setenv "top_srcdir" gpgme-srcdir #t)
(setenv "srcdir" (path-join gpgme-srcdir "tests" "gpg") #t) (setenv "srcdir" (path-join gpgme-srcdir "tests" "gpg") #t)
(define python (catch #f
(path-expand "python" (string-split (getenv "PATH") *pathsep*))))
(define (run what) (define (run what)
(if (string-suffix? (car what) ".py") (if (string-suffix? (car what) ".py")
(begin (begin
@ -39,15 +42,17 @@
(getenv "LD_LIBRARY_PATH")) (getenv "LD_LIBRARY_PATH"))
(path-join gpgme-builddir "src/.libs")) (path-join gpgme-builddir "src/.libs"))
#t) #t)
(call-with-fds (if python
`("/usr/bin/python" (call-with-fds
,(in-gpgme-srcdir "lang" "python" "tests" "run-tests.py") `(,python
--quiet ,(in-gpgme-srcdir "lang" "python" "tests" "run-tests.py")
--interpreters=/usr/bin/python --quiet
--builddir ,(path-join gpgme-builddir "lang" "python" "tests") ,(string-append "--interpreters=" python)
,@what) --builddir ,(path-join gpgme-builddir "lang" "python" "tests")
STDIN_FILENO STDOUT_FILENO STDERR_FILENO)) ,@what)
(if #f 77 (call-with-fds what STDIN_FILENO STDOUT_FILENO STDERR_FILENO)))) STDIN_FILENO STDOUT_FILENO STDERR_FILENO)
77))
(call-with-fds what STDIN_FILENO STDOUT_FILENO STDERR_FILENO)))
(let ((name (basename (car executable)))) (let ((name (basename (car executable))))
(cond (cond