projects/guix·blob python-team · refs

162 lines · 5.8 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015, 2025-2026 Ricardo Wurmus <[email protected]>
3;;; Copyright © 2017 Mathieu Othacehe <[email protected]>
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/>.
19
20(define-module (test-cran)
21 #:use-module (gnu packages statistics)
22 #:use-module (guix import cran)
23 #:use-module (guix sets)
24 #:use-module (guix tests)
25 #:use-module (srfi srfi-1)
26 #:use-module (srfi srfi-64)
27 #:use-module (srfi srfi-26)
28 #:use-module (ice-9 match))
29
30(define description "
31Package: My-Example
32Type: Package
33Title: Example package
34Version: 1.2.3
35Date: 2015-12-10
36Author: Ricardo Wurmus
37Maintainer: Guix Schmeeks <[email protected]>
38URL: http://gnu.org/s/my-example
39Description: This is a long description
40spanning multiple lines: and it could confuse the parser that this line is very long or perhaps the fact that
41there is a colon : on the lines.
42 And: this line continues the description.
43biocViews: 0
44SystemRequirements: Cairo (>= 0)
45Depends: A C++11 compiler. Version 4.6.* of g++ (as
46 currently in Rtools) is insufficient; versions 4.8.*, 4.9.* or
47 later will be fine.
48License: GPL (>= 3)
49Imports: Rcpp (>= 0.11.5), proto, Scales
50LinkingTo: Rcpp, BH
51NeedsCompilation: yes
52Repository: CRAN
53Date/Publication: 2015-07-14 14:15:16
54")
55
56(define description-alist
57 (description->alist description))
58
59(define simple-alist
60 '(("Key" . "Value")
61 ("SimpleList" . "R, Rcpp, something, whatever")
62 ("BadList" . "This is not a real list, you know?")
63 ("List" . "R (>= 2.2), BH (for no reason), GenomicRanges")))
64
65(test-begin "cran")
66
67(test-assert "description->alist: contains all valid keys"
68 (let ((keys '("Package" "Type" "Title" "Version" "Date"
69 "Author" "Maintainer" "URL" "Description"
70 "SystemRequirements" "Depends" "License"
71 "Imports" "biocViews" "LinkingTo"
72 "NeedsCompilation" "Repository"
73 "Date/Publication")))
74 (lset= string=? keys (map car description-alist))))
75
76(test-equal "listifyx: return empty list if key cannot be found"
77 '()
78 ((@@ (guix import cran) listify) simple-alist "Letters"))
79
80(test-equal "listify: split comma-separated value into elements"
81 '("R" "Rcpp" "something" "whatever")
82 ((@@ (guix import cran) listify) simple-alist "SimpleList"))
83
84(test-equal "listify: strip off parentheses"
85 '("R" "BH" "GenomicRanges")
86 ((@@ (guix import cran) listify) simple-alist "List"))
87
88(test-equal "listify: ignore values that are no lists"
89 '()
90 ((@@ (guix import cran) listify) simple-alist "BadList"))
91
92(test-equal "extract-imports: finds data.table"
93 (list "data.table")
94 (set->list ((@ (guix import cran) extract-imports) "abc + data.table::some_procedure()")))
95
96(test-equal "extract-imports: ignores text inside strings"
97 (list)
98 (set->list ((@ (guix import cran) extract-imports)
99 "\"hello::world\", \"this is not data.table::some_procedure(), actually\"")))
100
101(test-equal "extract-imports: extracts text inside single quotes"
102 (list "FDb.InfiniumMethylation.hg19")
103 (set->list ((@ (guix import cran) extract-imports)
104 "suppressPackageStartupMessages(require('FDb.InfiniumMethylation.hg19'))")))
105
106(test-equal "extract-imports: ignores other colon separated things"
107 (list)
108 (set->list ((@ (guix import cran) extract-imports)
109 "this:is:not::a:procedure")))
110
111(test-equal "extract-imports: matches things before a comma"
112 (list "MASS")
113 (set->list ((@ (guix import cran) extract-imports)
114 "check_installed(\"MASS\",")))
115
116(test-equal "r-minimal is not a cran package"
117 #f
118 ((@@ (guix import cran) cran-package?) r-minimal))
119
120(test-assert "description->package"
121 ;; Replace network resources with sample data.
122 (mock ((guix build download) url-fetch
123 (lambda* (url file-name
124 #:key
125 (mirrors '()) verify-certificate?)
126 (with-output-to-file file-name
127 (lambda ()
128 (display
129 (match url
130 ("mirror://cran/src/contrib/My-Example_1.2.3.tar.gz"
131 "source")
132 (_ (error "Unexpected URL: " url))))))))
133 (match (description->package 'cran description-alist)
134 (('package
135 ('name "r-my-example")
136 ('version "1.2.3")
137 ('source ('origin
138 ('method 'url-fetch)
139 ('uri ('cran-uri "My-Example" 'version))
140 ('sha256
141 ('base32
142 (? string? hash)))))
143 ('properties ('quasiquote (('upstream-name . "My-Example"))))
144 ('build-system 'r-build-system)
145 ('inputs ('list 'cairo))
146 ('propagated-inputs
147 ('list 'r-bh 'r-proto 'r-rcpp 'r-scales))
148 ('home-page "http://gnu.org/s/my-example")
149 ('synopsis "Example package")
150 ('description
151 "\
152This is a long description spanning multiple lines: and it could confuse the
153parser that this line is very long or perhaps the fact that there is a colon :
154on the lines. And: this line continues the description.")
155 ('license 'gpl3+))
156 #t)
157 (x
158 (begin
159 (format #t "~s\n" x)
160 (pk 'fail x #f))))))
161
162(test-end "cran")