diff options
| author | David Thompson <dthompson2@worcester.edu> | 2014-09-27 10:16:23 -0400 |
|---|---|---|
| committer | David Thompson <dthompson2@worcester.edu> | 2014-09-29 19:30:28 -0400 |
| commit | 1b3e968512ebbccf02d00c52f7e089156946f445 (patch) | |
| tree | c45d203439ab9a74d01f2c76850cafb847a755e2 /tests | |
| parent | 2efb3ddaa434b86a841dffbba89e21d2d9208526 (diff) | |
import: Add PyPI importer.
* guix/snix.scm: Delete.
* guix/import/snix.scm: New file.
* guix/import/pypi.scm: New file.
* guix/import/utils.scm: New file.
* guix/scripts/import/nix.scm: New file.
* guix/scripts/import/pypi.scm: New file.
* tests/pypi.scm: New file.
* tests/snix.scm: Import (guix import snix) module.
* guix/scripts/import.scm (%default-options, %options): Delete.
(%standard-import-options, importers): New variables.
(show-help): List importers.
(guix-import): Factor out Nix-specific logic. Delegate to correct importer
based upon first argument.
* configure.ac (HAVE_GUILE_JSON): New conditional.
* Makefile.am (MODULES): Add new files and remove 'guix/snix.scm'.
(SCM_TESTS): Add 'tests/pypi.scm' if guile-json is installed.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/pypi.scm | 102 | ||||
| -rw-r--r-- | tests/snix.scm | 4 |
2 files changed, 104 insertions, 2 deletions
diff --git a/tests/pypi.scm b/tests/pypi.scm new file mode 100644 index 00000000000..124c512d54b --- /dev/null +++ b/tests/pypi.scm | |||
| @@ -0,0 +1,102 @@ | |||
| 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) | ||
| 23 | #:use-module (srfi srfi-64) | ||
| 24 | #:use-module (ice-9 match)) | ||
| 25 | |||
| 26 | (define-syntax-rule (mock (module proc replacement) body ...) | ||
| 27 | (let* ((m (resolve-module 'module)) | ||
| 28 | (original (module-ref m 'proc))) | ||
| 29 | (dynamic-wind | ||
| 30 | (lambda () (module-set! m 'proc replacement)) | ||
| 31 | (lambda () body ...) | ||
| 32 | (lambda () (module-set! m 'proc original))))) | ||
| 33 | |||
| 34 | (define test-json | ||
| 35 | "{ | ||
| 36 | \"info\": { | ||
| 37 | \"version\": \"1.0.0\", | ||
| 38 | \"name\": \"foo\", | ||
| 39 | \"license\": \"GNU LGPL\", | ||
| 40 | \"summary\": \"summary\", | ||
| 41 | \"home_page\": \"http://example.com\", | ||
| 42 | }, | ||
| 43 | \"releases\": { | ||
| 44 | \"1.0.0\": [ | ||
| 45 | { | ||
| 46 | \"url\": \"https://example.com/foo-1.0.0.egg\", | ||
| 47 | \"packagetype\": \"bdist_egg\", | ||
| 48 | }, { | ||
| 49 | \"url\": \"https://example.com/foo-1.0.0.tar.gz\", | ||
| 50 | \"packagetype\": \"sdist\", | ||
| 51 | } | ||
| 52 | ] | ||
| 53 | } | ||
| 54 | }") | ||
| 55 | |||
| 56 | (define test-source | ||
| 57 | "foobar") | ||
| 58 | |||
| 59 | (test-begin "pypi") | ||
| 60 | |||
| 61 | (test-assert "pypi->guix-package" | ||
| 62 | ;; Replace network resources with sample data. | ||
| 63 | (mock ((guix import pypi) url-fetch | ||
| 64 | (lambda (url file-name) | ||
| 65 | (with-output-to-file file-name | ||
| 66 | (lambda () | ||
| 67 | (display | ||
| 68 | (match url | ||
| 69 | ("https://pypi.python.org/pypi/foo/json" | ||
| 70 | test-json) | ||
| 71 | ("https://example.com/foo-1.0.0.tar.gz" | ||
| 72 | test-source) | ||
| 73 | (_ (error "Unexpected URL: " url)))))))) | ||
| 74 | (match (pypi->guix-package "foo") | ||
| 75 | (('package | ||
| 76 | ('name "python-foo") | ||
| 77 | ('version "1.0.0") | ||
| 78 | ('source ('origin | ||
| 79 | ('method 'url-fetch) | ||
| 80 | ('uri ('string-append "https://example.com/foo-" | ||
| 81 | 'version ".tar.gz")) | ||
| 82 | ('sha256 | ||
| 83 | ('base32 | ||
| 84 | (? string? hash))))) | ||
| 85 | ('build-system 'python-build-system) | ||
| 86 | ('inputs | ||
| 87 | ('quasiquote | ||
| 88 | (("python-setuptools" ('unquote 'python-setuptools))))) | ||
| 89 | ('home-page "http://example.com") | ||
| 90 | ('synopsis "summary") | ||
| 91 | ('description "summary") | ||
| 92 | ('license 'lgpl2.0)) | ||
| 93 | (string=? (bytevector->nix-base32-string | ||
| 94 | (call-with-input-string test-source port-sha256)) | ||
| 95 | hash)) | ||
| 96 | (x | ||
| 97 | (pk 'fail x #f))))) | ||
| 98 | |||
| 99 | (test-end "pypi") | ||
| 100 | |||
| 101 | |||
| 102 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | ||
diff --git a/tests/snix.scm b/tests/snix.scm index 9d692e9c02d..2318780d3df 100644 --- a/tests/snix.scm +++ b/tests/snix.scm | |||
| @@ -17,14 +17,14 @@ | |||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | ||
| 19 | (define-module (test-snix) | 19 | (define-module (test-snix) |
| 20 | #:use-module (guix snix) | 20 | #:use-module (guix import snix) |
| 21 | #:use-module ((guix utils) #:select (%nixpkgs-directory)) | 21 | #:use-module ((guix utils) #:select (%nixpkgs-directory)) |
| 22 | #:use-module (srfi srfi-1) | 22 | #:use-module (srfi srfi-1) |
| 23 | #:use-module (srfi srfi-64) | 23 | #:use-module (srfi srfi-64) |
| 24 | #:use-module (ice-9 match)) | 24 | #:use-module (ice-9 match)) |
| 25 | 25 | ||
| 26 | (define factorize-uri | 26 | (define factorize-uri |
| 27 | (@@ (guix snix) factorize-uri)) | 27 | (@@ (guix import snix) factorize-uri)) |
| 28 | 28 | ||
| 29 | (define-syntax-rule (every? proc lists ...) | 29 | (define-syntax-rule (every? proc lists ...) |
| 30 | (not (not (every proc lists ...)))) | 30 | (not (not (every proc lists ...)))) |
