gnu: messaging: Add libsignal-protocol-c.
[guix.git] / tests / pypi.scm
blob74f13e96624fc2ab4246e3360085260f50c36bd5
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
3 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
20 (define-module (test-pypi)
21   #:use-module (guix import pypi)
22   #:use-module (guix base32)
23   #:use-module (guix hash)
24   #:use-module (guix tests)
25   #:use-module (guix build-system python)
26   #:use-module ((guix build utils) #:select (delete-file-recursively which))
27   #:use-module (srfi srfi-64)
28   #:use-module (ice-9 match))
30 (define test-json
31   "{
32   \"info\": {
33     \"version\": \"1.0.0\",
34     \"name\": \"foo\",
35     \"license\": \"GNU LGPL\",
36     \"summary\": \"summary\",
37     \"home_page\": \"http://example.com\",
38   },
39   \"releases\": {
40     \"1.0.0\": [
41       {
42         \"url\": \"https://example.com/foo-1.0.0.egg\",
43         \"packagetype\": \"bdist_egg\",
44       }, {
45         \"url\": \"https://example.com/foo-1.0.0.tar.gz\",
46         \"packagetype\": \"sdist\",
47       }, {
48         \"url\": \"https://example.com/foo-1.0.0-py2.py3-none-any.whl\",
49         \"packagetype\": \"bdist_wheel\",
50       }
51     ]
52   }
53 }")
55 (define test-source-hash
56   "")
58 (define test-requirements
59 "# A comment
60  # A comment after a space
61 bar
62 baz > 13.37")
64 (define test-metadata
65   "{
66   \"run_requires\": [
67     {
68       \"requires\": [
69         \"bar\",
70         \"baz (>13.37)\"
71       ]
72     }
73   ]
74 }")
76 (test-begin "pypi")
78 (test-equal "guix-package->pypi-name, old URL style"
79   "psutil"
80   (guix-package->pypi-name
81    (dummy-package "foo"
82                   (source (dummy-origin
83                            (uri
84                             "https://pypi.io/packages/source/p/psutil/psutil-4.3.0.tar.gz"))))))
86 (test-equal "guix-package->pypi-name, new URL style"
87   "certbot"
88   (guix-package->pypi-name
89    (dummy-package "foo"
90                   (source (dummy-origin
91                            (uri
92                             "https://pypi.python.org/packages/a2/3b/4756e6a0ceb14e084042a2a65c615d68d25621c6fd446d0fc10d14c4ce7d/certbot-0.8.1.tar.gz"))))))
94 (test-equal "guix-package->pypi-name, several URLs"
95   "cram"
96   (guix-package->pypi-name
97    (dummy-package "foo"
98                   (source
99                    (dummy-origin
100                     (uri (list "https://bitheap.org/cram/cram-0.7.tar.gz"
101                                (pypi-uri "cram" "0.7"))))))))
103 (test-assert "pypi->guix-package"
104   ;; Replace network resources with sample data.
105     (mock ((guix import utils) url-fetch
106            (lambda (url file-name)
107              (match url
108                ("https://example.com/foo-1.0.0.tar.gz"
109                 (begin
110                   (mkdir "foo-1.0.0")
111                   (with-output-to-file "foo-1.0.0/requirements.txt"
112                     (lambda ()
113                       (display test-requirements)))
114                   (system* "tar" "czvf" file-name "foo-1.0.0/")
115                   (delete-file-recursively "foo-1.0.0")
116                   (set! test-source-hash
117                     (call-with-input-file file-name port-sha256))))
118                ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
119                (_ (error "Unexpected URL: " url)))))
120           (mock ((guix http-client) http-fetch
121                  (lambda (url . rest)
122                    (match url
123                      ("https://pypi.python.org/pypi/foo/json"
124                       (values (open-input-string test-json)
125                               (string-length test-json)))
126                      ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
127                      (_ (error "Unexpected URL: " url)))))
128                 (match (pypi->guix-package "foo")
129                   (('package
130                      ('name "python-foo")
131                      ('version "1.0.0")
132                      ('source ('origin
133                                 ('method 'url-fetch)
134                                 ('uri ('pypi-uri "foo" 'version))
135                                 ('sha256
136                                  ('base32
137                                   (? string? hash)))))
138                      ('build-system 'python-build-system)
139                      ('propagated-inputs
140                       ('quasiquote
141                        (("python-bar" ('unquote 'python-bar))
142                         ("python-baz" ('unquote 'python-baz)))))
143                      ('home-page "http://example.com")
144                      ('synopsis "summary")
145                      ('description "summary")
146                      ('license 'license:lgpl2.0))
147                    (string=? (bytevector->nix-base32-string
148                               test-source-hash)
149                              hash))
150                   (x
151                    (pk 'fail x #f))))))
153 (test-skip (if (which "zip") 0 1))
154 (test-assert "pypi->guix-package, wheels"
155   ;; Replace network resources with sample data.
156   (mock ((guix import utils) url-fetch
157          (lambda (url file-name)
158            (match url
159              ("https://example.com/foo-1.0.0.tar.gz"
160                (begin
161                  (mkdir "foo-1.0.0")
162                  (with-output-to-file "foo-1.0.0/requirements.txt"
163                    (lambda ()
164                      (display test-requirements)))
165                  (system* "tar" "czvf" file-name "foo-1.0.0/")
166                  (delete-file-recursively "foo-1.0.0")
167                  (set! test-source-hash
168                        (call-with-input-file file-name port-sha256))))
169              ("https://example.com/foo-1.0.0-py2.py3-none-any.whl"
170                (begin
171                  (mkdir "foo-1.0.0.dist-info")
172                  (with-output-to-file "foo-1.0.0.dist-info/metadata.json"
173                    (lambda ()
174                      (display test-metadata)))
175                  (let ((zip-file (string-append file-name ".zip")))
176                    ;; zip always adds a "zip" extension to the file it creates,
177                    ;; so we need to rename it.
178                    (system* "zip" zip-file "foo-1.0.0.dist-info/metadata.json")
179                    (rename-file zip-file file-name))
180                  (delete-file-recursively "foo-1.0.0.dist-info")))
181              (_ (error "Unexpected URL: " url)))))
182         (mock ((guix http-client) http-fetch
183                (lambda (url . rest)
184                  (match url
185                    ("https://pypi.python.org/pypi/foo/json"
186                     (values (open-input-string test-json)
187                             (string-length test-json)))
188                    ("https://example.com/foo-1.0.0-py2.py3-none-any.whl" #f)
189                    (_ (error "Unexpected URL: " url)))))
190               (match (pypi->guix-package "foo")
191                 (('package
192                    ('name "python-foo")
193                    ('version "1.0.0")
194                    ('source ('origin
195                               ('method 'url-fetch)
196                               ('uri ('pypi-uri "foo" 'version))
197                               ('sha256
198                                ('base32
199                                 (? string? hash)))))
200                    ('build-system 'python-build-system)
201                    ('propagated-inputs
202                     ('quasiquote
203                      (("python-bar" ('unquote 'python-bar))
204                       ("python-baz" ('unquote 'python-baz)))))
205                    ('home-page "http://example.com")
206                    ('synopsis "summary")
207                    ('description "summary")
208                    ('license 'license:lgpl2.0))
209                  (string=? (bytevector->nix-base32-string
210                             test-source-hash)
211                            hash))
212                 (x
213                  (pk 'fail x #f))))))
215 (test-end "pypi")