Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / tests / pypi.scm
CommitLineData
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)
ff986890 24 #:use-module ((guix build utils) #:select (delete-file-recursively))
1b3e9685
DT
25 #:use-module (srfi srfi-64)
26 #:use-module (ice-9 match))
27
1b3e9685
DT
28(define test-json
29 "{
30 \"info\": {
31 \"version\": \"1.0.0\",
32 \"name\": \"foo\",
33 \"license\": \"GNU LGPL\",
34 \"summary\": \"summary\",
35 \"home_page\": \"http://example.com\",
36 },
37 \"releases\": {
38 \"1.0.0\": [
39 {
40 \"url\": \"https://example.com/foo-1.0.0.egg\",
41 \"packagetype\": \"bdist_egg\",
42 }, {
43 \"url\": \"https://example.com/foo-1.0.0.tar.gz\",
44 \"packagetype\": \"sdist\",
45 }
46 ]
47 }
48}")
49
ff986890
CR
50(define test-source-hash
51 "")
52
53(define test-requirements
54"# A comment
55 # A comment after a space
56bar
57baz > 13.37")
1b3e9685
DT
58
59(test-begin "pypi")
60
61(test-assert "pypi->guix-package"
62 ;; Replace network resources with sample data.
1ff2619b 63 (mock ((guix import utils) url-fetch
1b3e9685 64 (lambda (url file-name)
ff986890
CR
65 (match url
66 ("https://pypi.python.org/pypi/foo/json"
67 (with-output-to-file file-name
68 (lambda ()
69 (display test-json))))
70 ("https://example.com/foo-1.0.0.tar.gz"
71 (begin
72 (mkdir "foo-1.0.0")
73 (with-output-to-file "foo-1.0.0/requirements.txt"
74 (lambda ()
75 (display test-requirements)))
76 (system* "tar" "czvf" file-name "foo-1.0.0/")
77 (delete-file-recursively "foo-1.0.0")
78 (set! test-source-hash
79 (call-with-input-file file-name port-sha256))))
80 (_ (error "Unexpected URL: " url)))))
1b3e9685
DT
81 (match (pypi->guix-package "foo")
82 (('package
83 ('name "python-foo")
84 ('version "1.0.0")
85 ('source ('origin
86 ('method 'url-fetch)
d8bdd382 87 ('uri (pypi-uri "foo" version))
1b3e9685
DT
88 ('sha256
89 ('base32
90 (? string? hash)))))
91 ('build-system 'python-build-system)
92 ('inputs
93 ('quasiquote
ff986890
CR
94 (("python-bar" ('unquote 'python-bar))
95 ("python-baz" ('unquote 'python-baz))
96 ("python-setuptools" ('unquote 'python-setuptools)))))
1b3e9685
DT
97 ('home-page "http://example.com")
98 ('synopsis "summary")
99 ('description "summary")
100 ('license 'lgpl2.0))
101 (string=? (bytevector->nix-base32-string
ff986890 102 test-source-hash)
1b3e9685
DT
103 hash))
104 (x
105 (pk 'fail x #f)))))
106
107(test-end "pypi")
108
109\f
110(exit (= (test-runner-fail-count (test-runner-current)) 0))