You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

103 lines
3.2 KiB

  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. (define-module (test-pypi)
  19. #:use-module (guix import pypi)
  20. #:use-module (guix base32)
  21. #:use-module (guix hash)
  22. #:use-module (srfi srfi-64)
  23. #:use-module (ice-9 match))
  24. (define-syntax-rule (mock (module proc replacement) body ...)
  25. (let* ((m (resolve-module 'module))
  26. (original (module-ref m 'proc)))
  27. (dynamic-wind
  28. (lambda () (module-set! m 'proc replacement))
  29. (lambda () body ...)
  30. (lambda () (module-set! m 'proc original)))))
  31. (define test-json
  32. "{
  33. \"info\": {
  34. \"version\": \"1.0.0\",
  35. \"name\": \"foo\",
  36. \"license\": \"GNU LGPL\",
  37. \"summary\": \"summary\",
  38. \"home_page\": \"http://example.com\",
  39. },
  40. \"releases\": {
  41. \"1.0.0\": [
  42. {
  43. \"url\": \"https://example.com/foo-1.0.0.egg\",
  44. \"packagetype\": \"bdist_egg\",
  45. }, {
  46. \"url\": \"https://example.com/foo-1.0.0.tar.gz\",
  47. \"packagetype\": \"sdist\",
  48. }
  49. ]
  50. }
  51. }")
  52. (define test-source
  53. "foobar")
  54. (test-begin "pypi")
  55. (test-assert "pypi->guix-package"
  56. ;; Replace network resources with sample data.
  57. (mock ((guix import pypi) url-fetch
  58. (lambda (url file-name)
  59. (with-output-to-file file-name
  60. (lambda ()
  61. (display
  62. (match url
  63. ("https://pypi.python.org/pypi/foo/json"
  64. test-json)
  65. ("https://example.com/foo-1.0.0.tar.gz"
  66. test-source)
  67. (_ (error "Unexpected URL: " url))))))))
  68. (match (pypi->guix-package "foo")
  69. (('package
  70. ('name "python-foo")
  71. ('version "1.0.0")
  72. ('source ('origin
  73. ('method 'url-fetch)
  74. ('uri ('string-append "https://example.com/foo-"
  75. 'version ".tar.gz"))
  76. ('sha256
  77. ('base32
  78. (? string? hash)))))
  79. ('build-system 'python-build-system)
  80. ('inputs
  81. ('quasiquote
  82. (("python-setuptools" ('unquote 'python-setuptools)))))
  83. ('home-page "http://example.com")
  84. ('synopsis "summary")
  85. ('description "summary")
  86. ('license 'lgpl2.0))
  87. (string=? (bytevector->nix-base32-string
  88. (call-with-input-string test-source port-sha256))
  89. hash))
  90. (x
  91. (pk 'fail x #f)))))
  92. (test-end "pypi")
  93. (exit (= (test-runner-fail-count (test-runner-current)) 0))