From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Bavier Subject: [PATCH 3/4] tests: import: Factorize utility function. Date: Thu, 8 Jan 2015 15:45:53 -0600 Message-ID: <1420753555-15767-3-git-send-email-bavier@member.fsf.org> References: <1420753555-15767-1-git-send-email-bavier@member.fsf.org> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9KtN-0001rC-4d for guix-devel@gnu.org; Thu, 08 Jan 2015 16:45:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9KtI-0002Dp-2t for guix-devel@gnu.org; Thu, 08 Jan 2015 16:45:21 -0500 Received: from mail-ie0-x230.google.com ([2607:f8b0:4001:c03::230]:40586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9KtH-0002Dk-TI for guix-devel@gnu.org; Thu, 08 Jan 2015 16:45:16 -0500 Received: by mail-ie0-f176.google.com with SMTP id tr6so11934824ieb.7 for ; Thu, 08 Jan 2015 13:45:15 -0800 (PST) In-Reply-To: <1420753555-15767-1-git-send-email-bavier@member.fsf.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org * tests/pypi.scm (mock): Move this... * guix/tests.scm: to here. --- guix/tests.scm | 11 +++++++++++ tests/pypi.scm | 9 +-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/guix/tests.scm b/guix/tests.scm index 0226799..e63cded 100644 --- a/guix/tests.scm +++ b/guix/tests.scm @@ -27,6 +27,7 @@ #:export (open-connection-for-tests random-text random-bytevector + mock with-derivation-narinfo)) ;;; Commentary: @@ -69,6 +70,16 @@ (loop (1+ i))) 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. diff --git a/tests/pypi.scm b/tests/pypi.scm index 53c34d9..45cf7ca 100644 --- a/tests/pypi.scm +++ b/tests/pypi.scm @@ -20,17 +20,10 @@ #:use-module (guix import pypi) #:use-module (guix base32) #:use-module (guix hash) + #:use-module (guix tests) #:use-module (srfi srfi-64) #: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 "{ \"info\": { -- 1.7.9.5