Commit | Line | Data |
---|---|---|
1b3e9685 DT |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2014 David Thompson <davet@gnu.org> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
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. | |
10 | ;;; | |
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. | |
15 | ;;; | |
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/>. | |
18 | ||
19 | (define-module (test-pypi) | |
20 | #:use-module (guix import pypi) | |
21 | #:use-module (guix base32) | |
22 | #:use-module (guix hash) | |
694b317c | 23 | #:use-module (guix tests) |
1b3e9685 DT |
24 | #:use-module (srfi srfi-64) |
25 | #:use-module (ice-9 match)) | |
26 | ||
1b3e9685 DT |
27 | (define test-json |
28 | "{ | |
29 | \"info\": { | |
30 | \"version\": \"1.0.0\", | |
31 | \"name\": \"foo\", | |
32 | \"license\": \"GNU LGPL\", | |
33 | \"summary\": \"summary\", | |
34 | \"home_page\": \"http://example.com\", | |
35 | }, | |
36 | \"releases\": { | |
37 | \"1.0.0\": [ | |
38 | { | |
39 | \"url\": \"https://example.com/foo-1.0.0.egg\", | |
40 | \"packagetype\": \"bdist_egg\", | |
41 | }, { | |
42 | \"url\": \"https://example.com/foo-1.0.0.tar.gz\", | |
43 | \"packagetype\": \"sdist\", | |
44 | } | |
45 | ] | |
46 | } | |
47 | }") | |
48 | ||
49 | (define test-source | |
50 | "foobar") | |
51 | ||
52 | (test-begin "pypi") | |
53 | ||
54 | (test-assert "pypi->guix-package" | |
55 | ;; Replace network resources with sample data. | |
1ff2619b | 56 | (mock ((guix import utils) url-fetch |
1b3e9685 DT |
57 | (lambda (url file-name) |
58 | (with-output-to-file file-name | |
59 | (lambda () | |
60 | (display | |
61 | (match url | |
62 | ("https://pypi.python.org/pypi/foo/json" | |
63 | test-json) | |
64 | ("https://example.com/foo-1.0.0.tar.gz" | |
65 | test-source) | |
66 | (_ (error "Unexpected URL: " url)))))))) | |
67 | (match (pypi->guix-package "foo") | |
68 | (('package | |
69 | ('name "python-foo") | |
70 | ('version "1.0.0") | |
71 | ('source ('origin | |
72 | ('method 'url-fetch) | |
73 | ('uri ('string-append "https://example.com/foo-" | |
74 | 'version ".tar.gz")) | |
75 | ('sha256 | |
76 | ('base32 | |
77 | (? string? hash))))) | |
78 | ('build-system 'python-build-system) | |
79 | ('inputs | |
80 | ('quasiquote | |
81 | (("python-setuptools" ('unquote 'python-setuptools))))) | |
82 | ('home-page "http://example.com") | |
83 | ('synopsis "summary") | |
84 | ('description "summary") | |
85 | ('license 'lgpl2.0)) | |
86 | (string=? (bytevector->nix-base32-string | |
87 | (call-with-input-string test-source port-sha256)) | |
88 | hash)) | |
89 | (x | |
90 | (pk 'fail x #f))))) | |
91 | ||
92 | (test-end "pypi") | |
93 | ||
94 | \f | |
95 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) |