tests: Mock up http-fetch in import tests.

This is a follow-up to commit 63773200d7.

* tests/gem.scm ("gem->guix-package"): Replace mock definition of
"url-fetch" with "http-fetch".
* tests/pypi.scm ("pypi->guix-package"): Add mock definition of
"http-fetch".
This commit is contained in:
Ricardo Wurmus 2016-12-18 09:55:17 +01:00
parent 51d8395ac6
commit 506abddb99
No known key found for this signature in database
GPG Key ID: 197A5888235FACAC
2 changed files with 55 additions and 50 deletions

View File

@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015 David Thompson <davet@gnu.org> ;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -45,13 +46,12 @@
(test-assert "gem->guix-package" (test-assert "gem->guix-package"
;; Replace network resources with sample data. ;; Replace network resources with sample data.
(mock ((guix import utils) url-fetch (mock ((guix http-client) http-fetch
(lambda (url file-name) (lambda (url)
(match url (match url
("https://rubygems.org/api/v1/gems/foo.json" ("https://rubygems.org/api/v1/gems/foo.json"
(with-output-to-file file-name (values (open-input-string test-json)
(lambda () (string-length test-json)))
(display test-json))))
(_ (error "Unexpected URL: " url))))) (_ (error "Unexpected URL: " url)))))
(match (gem->guix-package "foo") (match (gem->guix-package "foo")
(('package (('package

View File

@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014 David Thompson <davet@gnu.org> ;;; Copyright © 2014 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -94,10 +95,6 @@ baz > 13.37")
(mock ((guix import utils) url-fetch (mock ((guix import utils) url-fetch
(lambda (url file-name) (lambda (url file-name)
(match url (match url
("https://pypi.python.org/pypi/foo/json"
(with-output-to-file file-name
(lambda ()
(display test-json))))
("https://example.com/foo-1.0.0.tar.gz" ("https://example.com/foo-1.0.0.tar.gz"
(begin (begin
(mkdir "foo-1.0.0") (mkdir "foo-1.0.0")
@ -110,6 +107,14 @@ baz > 13.37")
(call-with-input-file file-name port-sha256)))) (call-with-input-file file-name port-sha256))))
("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f) ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
(_ (error "Unexpected URL: " url))))) (_ (error "Unexpected URL: " url)))))
(mock ((guix http-client) http-fetch
(lambda (url)
(match url
("https://pypi.python.org/pypi/foo/json"
(values (open-input-string test-json)
(string-length test-json)))
("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
(_ (error "Unexpected URL: " url)))))
(match (pypi->guix-package "foo") (match (pypi->guix-package "foo")
(('package (('package
('name "python-foo") ('name "python-foo")
@ -135,7 +140,7 @@ baz > 13.37")
test-source-hash) test-source-hash)
hash)) hash))
(x (x
(pk 'fail x #f))))) (pk 'fail x #f))))))
(test-skip (if (which "zip") 0 1)) (test-skip (if (which "zip") 0 1))
(test-assert "pypi->guix-package, wheels" (test-assert "pypi->guix-package, wheels"