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:
parent
51d8395ac6
commit
506abddb99
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
;;;
|
;;;
|
||||||
|
@ -91,51 +92,55 @@ baz > 13.37")
|
||||||
|
|
||||||
(test-assert "pypi->guix-package"
|
(test-assert "pypi->guix-package"
|
||||||
;; Replace network resources with sample data.
|
;; Replace network resources with sample data.
|
||||||
(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"
|
("https://example.com/foo-1.0.0.tar.gz"
|
||||||
(with-output-to-file file-name
|
(begin
|
||||||
(lambda ()
|
(mkdir "foo-1.0.0")
|
||||||
(display test-json))))
|
(with-output-to-file "foo-1.0.0/requirements.txt"
|
||||||
("https://example.com/foo-1.0.0.tar.gz"
|
(lambda ()
|
||||||
(begin
|
(display test-requirements)))
|
||||||
(mkdir "foo-1.0.0")
|
(system* "tar" "czvf" file-name "foo-1.0.0/")
|
||||||
(with-output-to-file "foo-1.0.0/requirements.txt"
|
(delete-file-recursively "foo-1.0.0")
|
||||||
(lambda ()
|
(set! test-source-hash
|
||||||
(display test-requirements)))
|
(call-with-input-file file-name port-sha256))))
|
||||||
(system* "tar" "czvf" file-name "foo-1.0.0/")
|
("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
|
||||||
(delete-file-recursively "foo-1.0.0")
|
(_ (error "Unexpected URL: " url)))))
|
||||||
(set! test-source-hash
|
(mock ((guix http-client) http-fetch
|
||||||
(call-with-input-file file-name port-sha256))))
|
(lambda (url)
|
||||||
("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
|
(match url
|
||||||
(_ (error "Unexpected URL: " url)))))
|
("https://pypi.python.org/pypi/foo/json"
|
||||||
(match (pypi->guix-package "foo")
|
(values (open-input-string test-json)
|
||||||
(('package
|
(string-length test-json)))
|
||||||
('name "python-foo")
|
("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
|
||||||
('version "1.0.0")
|
(_ (error "Unexpected URL: " url)))))
|
||||||
('source ('origin
|
(match (pypi->guix-package "foo")
|
||||||
('method 'url-fetch)
|
(('package
|
||||||
('uri (string-append "https://example.com/foo-"
|
('name "python-foo")
|
||||||
version ".tar.gz"))
|
('version "1.0.0")
|
||||||
('sha256
|
('source ('origin
|
||||||
('base32
|
('method 'url-fetch)
|
||||||
(? string? hash)))))
|
('uri (string-append "https://example.com/foo-"
|
||||||
('build-system 'python-build-system)
|
version ".tar.gz"))
|
||||||
('propagated-inputs
|
('sha256
|
||||||
('quasiquote
|
('base32
|
||||||
(("python-bar" ('unquote 'python-bar))
|
(? string? hash)))))
|
||||||
("python-baz" ('unquote 'python-baz))
|
('build-system 'python-build-system)
|
||||||
("python-setuptools" ('unquote 'python-setuptools)))))
|
('propagated-inputs
|
||||||
('home-page "http://example.com")
|
('quasiquote
|
||||||
('synopsis "summary")
|
(("python-bar" ('unquote 'python-bar))
|
||||||
('description "summary")
|
("python-baz" ('unquote 'python-baz))
|
||||||
('license 'license:lgpl2.0))
|
("python-setuptools" ('unquote 'python-setuptools)))))
|
||||||
(string=? (bytevector->nix-base32-string
|
('home-page "http://example.com")
|
||||||
test-source-hash)
|
('synopsis "summary")
|
||||||
hash))
|
('description "summary")
|
||||||
(x
|
('license 'license:lgpl2.0))
|
||||||
(pk 'fail x #f)))))
|
(string=? (bytevector->nix-base32-string
|
||||||
|
test-source-hash)
|
||||||
|
hash))
|
||||||
|
(x
|
||||||
|
(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"
|
||||||
|
|
Loading…
Reference in New Issue