tests: import: Factorize utility function.

* tests/pypi.scm (mock): Move this...
* guix/tests.scm: to here.
This commit is contained in:
Eric Bavier 2015-01-08 14:41:15 -06:00
parent 1ff2619bc1
commit 694b317c2d
2 changed files with 12 additions and 8 deletions

View file

@ -27,6 +27,7 @@ (define-module (guix tests)
#:export (open-connection-for-tests #:export (open-connection-for-tests
random-text random-text
random-bytevector random-bytevector
mock
with-derivation-narinfo with-derivation-narinfo
dummy-package)) dummy-package))
@ -70,6 +71,16 @@ (define (random-bytevector n)
(loop (1+ i))) (loop (1+ i)))
bv)))) bv))))
(define-syntax-rule (mock (module proc replacement) body ...)
"Within BODY, replace the definition of PROC from MODULE with the definition
given by REPLACEMENT."
(let* ((m (resolve-module 'module))
(original (module-ref m 'proc)))
(dynamic-wind
(lambda () (module-set! m 'proc replacement))
(lambda () body ...)
(lambda () (module-set! m 'proc original)))))
;;; ;;;
;;; Narinfo files, as used by the substituter. ;;; Narinfo files, as used by the substituter.

View file

@ -20,17 +20,10 @@ (define-module (test-pypi)
#:use-module (guix import pypi) #:use-module (guix import pypi)
#:use-module (guix base32) #:use-module (guix base32)
#:use-module (guix hash) #:use-module (guix hash)
#:use-module (guix tests)
#:use-module (srfi srfi-64) #:use-module (srfi srfi-64)
#:use-module (ice-9 match)) #:use-module (ice-9 match))
(define-syntax-rule (mock (module proc replacement) body ...)
(let* ((m (resolve-module 'module))
(original (module-ref m 'proc)))
(dynamic-wind
(lambda () (module-set! m 'proc replacement))
(lambda () body ...)
(lambda () (module-set! m 'proc original)))))
(define test-json (define test-json
"{ "{
\"info\": { \"info\": {