1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-pypi)
20 #:use-module (guix import pypi)
21 #:use-module (guix base32)
22 #:use-module (guix hash)
23 #:use-module (srfi srfi-64)
24 #:use-module (ice-9 match))
26 (define-syntax-rule (mock (module proc replacement) body ...)
27 (let* ((m (resolve-module 'module))
28 (original (module-ref m 'proc)))
30 (lambda () (module-set! m 'proc replacement))
32 (lambda () (module-set! m 'proc original)))))
37 \"version\": \"1.0.0\",
39 \"license\": \"GNU LGPL\",
40 \"summary\": \"summary\",
41 \"home_page\": \"http://example.com\",
46 \"url\": \"https://example.com/foo-1.0.0.egg\",
47 \"packagetype\": \"bdist_egg\",
49 \"url\": \"https://example.com/foo-1.0.0.tar.gz\",
50 \"packagetype\": \"sdist\",
61 (test-assert "pypi->guix-package"
62 ;; Replace network resources with sample data.
63 (mock ((guix import utils) url-fetch
64 (lambda (url file-name)
65 (with-output-to-file file-name
69 ("https://pypi.python.org/pypi/foo/json"
71 ("https://example.com/foo-1.0.0.tar.gz"
73 (_ (error "Unexpected URL: " url))))))))
74 (match (pypi->guix-package "foo")
80 ('uri ('string-append "https://example.com/foo-"
85 ('build-system 'python-build-system)
88 (("python-setuptools" ('unquote 'python-setuptools)))))
89 ('home-page "http://example.com")
91 ('description "summary")
93 (string=? (bytevector->nix-base32-string
94 (call-with-input-string test-source port-sha256))
102 (exit (= (test-runner-fail-count (test-runner-current)) 0))