Coverage for rust2rpm/tests/test_metadata.py: 100%
9 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-27 15:21 +0100
« prev ^ index » next coverage.py v7.6.4, created at 2024-10-27 15:21 +0100
1import pytest
3from cargo2rpm.semver import Comparator, Op as Operator
5from rust2rpm.metadata import package_uses_rust_1_60_feature_syntax, _is_strict_dep
8# test input derived from test fixtures in cargo2rpm
9@pytest.mark.parametrize(
10 "name,features,expected",
11 [
12 (
13 "ahash-0.8.3",
14 {
15 "atomic-polyfill": ["dep:atomic-polyfill", "once_cell/atomic-polyfill"],
16 "compile-time-rng": ["const-random"],
17 "const-random": ["dep:const-random"],
18 "default": ["std", "runtime-rng"],
19 "getrandom": ["dep:getrandom"],
20 "no-rng": [],
21 "runtime-rng": ["getrandom"],
22 "serde": ["dep:serde"],
23 "std": [],
24 },
25 True,
26 ),
27 (
28 "assert_cmd-2.0.8",
29 {
30 "color": ["dep:yansi", "dep:concolor", "concolor?/std", "predicates/color"],
31 "color-auto": ["color", "concolor?/auto"],
32 },
33 True,
34 ),
35 (
36 "assert_fs-1.0.10",
37 {
38 "color": ["dep:yansi", "dep:concolor", "predicates/color"],
39 "color-auto": ["color", "concolor?/auto"],
40 },
41 True,
42 ),
43 ("autocfg-1.1.0", {}, False),
44 (
45 "bstr-1.2.0",
46 {
47 "alloc": ["serde?/alloc"],
48 "default": ["std", "unicode"],
49 "serde": ["dep:serde"],
50 "std": ["alloc", "memchr/std", "serde?/std"],
51 "unicode": ["dep:once_cell", "dep:regex-automata"],
52 },
53 True,
54 ),
55 (
56 "cfg-if-1.0.0",
57 {
58 "compiler_builtins": ["dep:compiler_builtins"],
59 "core": ["dep:core"],
60 "rustc-dep-of-std": ["core", "compiler_builtins"],
61 },
62 False,
63 ),
64 (
65 "clap-4.1.4",
66 {
67 "cargo": ["dep:once_cell"],
68 "color": ["dep:is-terminal", "dep:termcolor"],
69 "debug": ["clap_derive?/debug", "dep:backtrace"],
70 "default": ["std", "color", "help", "usage", "error-context", "suggestions"],
71 "deprecated": ["clap_derive?/deprecated"],
72 "derive": ["dep:clap_derive", "dep:once_cell"],
73 "env": [],
74 "error-context": [],
75 "help": [],
76 "std": [],
77 "string": [],
78 "suggestions": ["dep:strsim", "error-context"],
79 "unicode": ["dep:unicode-width", "dep:unicase"],
80 "unstable-doc": ["derive", "cargo", "wrap_help", "env", "unicode", "string", "unstable-replace"],
81 "unstable-grouped": [],
82 "unstable-replace": [],
83 "unstable-v5": ["clap_derive?/unstable-v5", "deprecated"],
84 "usage": [],
85 "wrap_help": ["help", "dep:terminal_size"],
86 },
87 True,
88 ),
89 (
90 "gstreamer-0.19.7",
91 {
92 "default": [],
93 "dox": ["ffi/dox", "glib/dox", "serde"],
94 "serde": ["num-rational/serde", "dep:serde", "serde_bytes"],
95 "serde_bytes": ["dep:serde_bytes"],
96 "v1_16": ["ffi/v1_16"],
97 "v1_18": ["ffi/v1_18", "v1_16"],
98 "v1_20": ["ffi/v1_20", "v1_18"],
99 "v1_22": ["ffi/v1_22", "v1_20"],
100 },
101 True,
102 ),
103 (
104 "human-panic-1.1.0",
105 {"color": ["dep:termcolor", "dep:concolor"], "default": ["color"], "nightly": []},
106 True,
107 ),
108 ("hyperfine-1.15.0", {"windows_process_extensions_main_thread_handle": []}, False),
109 (
110 "libc-0.2.139",
111 {
112 "align": [],
113 "const-extern-fn": [],
114 "default": ["std"],
115 "extra_traits": [],
116 "rustc-dep-of-std": ["align", "rustc-std-workspace-core"],
117 "rustc-std-workspace-core": ["dep:rustc-std-workspace-core"],
118 "std": [],
119 "use_std": ["std"],
120 },
121 False,
122 ),
123 (
124 "predicates-2.1.5",
125 {
126 "color": ["dep:yansi", "dep:concolor", "concolor?/std"],
127 "color-auto": ["color", "concolor?/auto"],
128 "default": ["diff", "regex", "float-cmp", "normalize-line-endings"],
129 "diff": ["dep:difflib"],
130 "float-cmp": ["dep:float-cmp"],
131 "normalize-line-endings": ["dep:normalize-line-endings"],
132 "regex": ["dep:regex"],
133 "unstable": [],
134 },
135 True,
136 ),
137 (
138 "proc-macro2-1.0.50",
139 {"default": ["proc-macro"], "nightly": [], "proc-macro": [], "span-locations": []},
140 False,
141 ),
142 ("quote-1.0.23", {"default": ["proc-macro"], "proc-macro": ["proc-macro2/proc-macro"]}, False),
143 (
144 "rand-0.8.5",
145 {
146 "alloc": ["rand_core/alloc"],
147 "default": ["std", "std_rng"],
148 "getrandom": ["rand_core/getrandom"],
149 "libc": ["dep:libc"],
150 "log": ["dep:log"],
151 "min_const_gen": [],
152 "nightly": [],
153 "packed_simd": ["dep:packed_simd"],
154 "rand_chacha": ["dep:rand_chacha"],
155 "serde": ["dep:serde"],
156 "serde1": ["serde", "rand_core/serde1"],
157 "simd_support": ["packed_simd"],
158 "small_rng": [],
159 "std": ["rand_core/std", "rand_chacha/std", "alloc", "getrandom", "libc"],
160 "std_rng": ["rand_chacha"],
161 },
162 False,
163 ),
164 (
165 "rand_core-0.6.4",
166 {
167 "alloc": [],
168 "getrandom": ["dep:getrandom"],
169 "serde": ["dep:serde"],
170 "serde1": ["serde"],
171 "std": ["alloc", "getrandom", "getrandom/std"],
172 },
173 False,
174 ),
175 ("rpm-sequoia-1.2.0", {"default": ["sequoia-openpgp/crypto-nettle"]}, False),
176 (
177 "rust_decimal-1.28.0",
178 {
179 "arbitrary": ["dep:arbitrary"],
180 "borsh": ["dep:borsh"],
181 "bytecheck": ["dep:bytecheck"],
182 "byteorder": ["dep:byteorder"],
183 "bytes": ["dep:bytes"],
184 "c-repr": [],
185 "db-diesel-mysql": ["db-diesel1-mysql"],
186 "db-diesel-postgres": ["db-diesel1-postgres"],
187 "db-diesel1-mysql": ["diesel1/mysql", "std"],
188 "db-diesel1-postgres": ["diesel1/postgres", "std"],
189 "db-diesel2-mysql": ["diesel2/mysql", "std"],
190 "db-diesel2-postgres": ["diesel2/postgres", "std"],
191 "db-postgres": ["byteorder", "bytes", "postgres", "std"],
192 "db-tokio-postgres": ["byteorder", "bytes", "postgres", "std", "tokio-postgres"],
193 "default": ["serde", "std"],
194 "diesel1": ["dep:diesel1"],
195 "diesel2": ["dep:diesel2"],
196 "legacy-ops": [],
197 "maths": [],
198 "maths-nopanic": ["maths"],
199 "postgres": ["dep:postgres"],
200 "rand": ["dep:rand"],
201 "rkyv": ["dep:rkyv"],
202 "rkyv-safe": ["bytecheck", "rkyv/validation"],
203 "rocket": ["dep:rocket"],
204 "rocket-traits": ["rocket"],
205 "rust-fuzz": ["arbitrary"],
206 "serde": ["dep:serde"],
207 "serde-arbitrary-precision": ["serde-with-arbitrary-precision"],
208 "serde-bincode": ["serde-str"],
209 "serde-float": ["serde-with-float"],
210 "serde-str": ["serde-with-str"],
211 "serde-with-arbitrary-precision": ["serde", "serde_json/arbitrary_precision", "serde_json/std"],
212 "serde-with-float": ["serde"],
213 "serde-with-str": ["serde"],
214 "serde_json": ["dep:serde_json"],
215 "std": [
216 "arrayvec/std",
217 "borsh?/std",
218 "bytecheck?/std",
219 "byteorder?/std",
220 "bytes?/std",
221 "rand?/std",
222 "rkyv?/std",
223 "serde?/std",
224 "serde_json?/std",
225 ],
226 "tokio-pg": ["db-tokio-postgres"],
227 "tokio-postgres": ["dep:tokio-postgres"],
228 },
229 True,
230 ),
231 (
232 "rustix-0.36.8",
233 {
234 "all-apis": [
235 "fs",
236 "io_uring",
237 "mm",
238 "net",
239 "param",
240 "process",
241 "procfs",
242 "rand",
243 "runtime",
244 "termios",
245 "thread",
246 "time",
247 ],
248 "all-impls": ["os_pipe", "fs-err"],
249 "alloc": ["dep:alloc"],
250 "cc": ["dep:cc"],
251 "compiler_builtins": ["dep:compiler_builtins"],
252 "core": ["dep:core"],
253 "default": ["std", "use-libc-auxv"],
254 "fs": [],
255 "fs-err": ["io-lifetimes/fs-err"],
256 "io-lifetimes": ["dep:io-lifetimes"],
257 "io_uring": ["fs", "net"],
258 "itoa": ["dep:itoa"],
259 "libc": ["dep:libc"],
260 "libc_errno": ["dep:libc_errno"],
261 "mm": [],
262 "net": [],
263 "once_cell": ["dep:once_cell"],
264 "os_pipe": ["io-lifetimes/os_pipe"],
265 "param": ["fs"],
266 "process": [],
267 "procfs": ["once_cell", "itoa", "fs"],
268 "rand": [],
269 "runtime": [],
270 "rustc-dep-of-std": [
271 "core",
272 "alloc",
273 "compiler_builtins",
274 "linux-raw-sys/rustc-dep-of-std",
275 "bitflags/rustc-dep-of-std",
276 ],
277 "std": ["io-lifetimes"],
278 "termios": [],
279 "thread": [],
280 "time": [],
281 "use-libc": ["libc_errno", "libc"],
282 "use-libc-auxv": ["libc"],
283 },
284 False,
285 ),
286 (
287 "serde-1.0.152",
288 {
289 "alloc": [],
290 "default": ["std"],
291 "derive": ["serde_derive"],
292 "rc": [],
293 "serde_derive": ["dep:serde_derive"],
294 "std": [],
295 "unstable": [],
296 },
297 False,
298 ),
299 ("serde_derive-1.0.152", {"default": [], "deserialize_in_place": []}, False),
300 (
301 "syn-1.0.107",
302 {
303 "clone-impls": [],
304 "default": ["derive", "parsing", "printing", "clone-impls", "proc-macro"],
305 "derive": [],
306 "extra-traits": [],
307 "fold": [],
308 "full": [],
309 "parsing": [],
310 "printing": ["quote"],
311 "proc-macro": ["proc-macro2/proc-macro", "quote/proc-macro"],
312 "quote": ["dep:quote"],
313 "test": ["syn-test-suite/all-features"],
314 "visit": [],
315 "visit-mut": [],
316 },
317 False,
318 ),
319 (
320 "time-0.3.17",
321 {
322 "alloc": ["serde?/alloc"],
323 "default": ["std"],
324 "formatting": ["dep:itoa", "std", "time-macros?/formatting"],
325 "large-dates": ["time-macros?/large-dates"],
326 "local-offset": ["std", "dep:libc", "dep:num_threads"],
327 "macros": ["dep:time-macros"],
328 "parsing": ["time-macros?/parsing"],
329 "quickcheck": ["dep:quickcheck", "alloc"],
330 "rand": ["dep:rand"],
331 "serde": ["dep:serde", "time-macros?/serde"],
332 "serde-human-readable": ["serde", "formatting", "parsing"],
333 "serde-well-known": ["serde", "formatting", "parsing"],
334 "std": ["alloc"],
335 "wasm-bindgen": ["dep:js-sys"],
336 },
337 True,
338 ),
339 (
340 "tokio-1.25.0",
341 {
342 "bytes": ["dep:bytes"],
343 "default": [],
344 "fs": [],
345 "full": [
346 "fs",
347 "io-util",
348 "io-std",
349 "macros",
350 "net",
351 "parking_lot",
352 "process",
353 "rt",
354 "rt-multi-thread",
355 "signal",
356 "sync",
357 "time",
358 ],
359 "io-std": [],
360 "io-util": ["memchr", "bytes"],
361 "libc": ["dep:libc"],
362 "macros": ["tokio-macros"],
363 "memchr": ["dep:memchr"],
364 "mio": ["dep:mio"],
365 "net": [
366 "libc",
367 "mio/os-poll",
368 "mio/os-ext",
369 "mio/net",
370 "socket2",
371 "windows-sys/Win32_Foundation",
372 "windows-sys/Win32_Security",
373 "windows-sys/Win32_Storage_FileSystem",
374 "windows-sys/Win32_System_Pipes",
375 "windows-sys/Win32_System_SystemServices",
376 ],
377 "num_cpus": ["dep:num_cpus"],
378 "parking_lot": ["dep:parking_lot"],
379 "process": [
380 "bytes",
381 "libc",
382 "mio/os-poll",
383 "mio/os-ext",
384 "mio/net",
385 "signal-hook-registry",
386 "windows-sys/Win32_Foundation",
387 "windows-sys/Win32_System_Threading",
388 "windows-sys/Win32_System_WindowsProgramming",
389 ],
390 "rt": [],
391 "rt-multi-thread": ["num_cpus", "rt"],
392 "signal": [
393 "libc",
394 "mio/os-poll",
395 "mio/net",
396 "mio/os-ext",
397 "signal-hook-registry",
398 "windows-sys/Win32_Foundation",
399 "windows-sys/Win32_System_Console",
400 ],
401 "signal-hook-registry": ["dep:signal-hook-registry"],
402 "socket2": ["dep:socket2"],
403 "stats": [],
404 "sync": [],
405 "test-util": ["rt", "sync", "time"],
406 "time": [],
407 "tokio-macros": ["dep:tokio-macros"],
408 "tracing": ["dep:tracing"],
409 "windows-sys": ["dep:windows-sys"],
410 },
411 False,
412 ),
413 ("unicode-xid-0.2.4", {"bench": [], "default": [], "no_std": []}, False),
414 (
415 "zbus-3.8.0",
416 {
417 "async-executor": ["dep:async-executor"],
418 "async-io": ["dep:async-io", "async-executor", "async-task", "async-lock"],
419 "async-lock": ["dep:async-lock"],
420 "async-task": ["dep:async-task"],
421 "chrono": ["zvariant/chrono"],
422 "default": ["async-io"],
423 "gvariant": ["zvariant/gvariant"],
424 "lazy_static": ["dep:lazy_static"],
425 "quick-xml": ["dep:quick-xml"],
426 "serde-xml-rs": ["dep:serde-xml-rs"],
427 "time": ["zvariant/time"],
428 "tokio": ["dep:tokio", "lazy_static"],
429 "tokio-vsock": ["dep:tokio-vsock", "tokio"],
430 "url": ["zvariant/url"],
431 "uuid": ["zvariant/uuid"],
432 "vsock": ["dep:vsock", "dep:async-io"],
433 "windows-gdbus": [],
434 "xml": ["serde-xml-rs"],
435 },
436 True,
437 ),
438 ("zoxide-0.9.0", {"default": [], "nix-dev": []}, False),
439 ],
440)
441def test_package_uses_rust_1_60_feature_syntax(name: str, features: dict[str, list[str]], expected: bool):
442 assert package_uses_rust_1_60_feature_syntax(features) == expected
445@pytest.mark.parametrize(
446 "comp,expected",
447 [
448 (Comparator(Operator.TILDE, 0, 1, None, None), False),
449 (Comparator(Operator.TILDE, 0, None, None, None), False),
450 (Comparator(Operator.TILDE, 1, None, None, None), False),
451 (Comparator(Operator.TILDE, 1, 0, None, None), True),
452 (Comparator(Operator.CARET, 1, 0, None, None), False),
453 (Comparator(Operator.WILDCARD, 0, 1, None, None), False),
454 (Comparator(Operator.WILDCARD, 1, 0, None, None), True),
455 (Comparator(Operator.WILDCARD, 1, None, None, None), False),
456 (Comparator(Operator.EXACT, 1, 2, None, None), True),
457 (Comparator(Operator.EXACT, 1, 2, 3, None), False),
458 (Comparator(Operator.EXACT, 0, 1, None, None), False),
459 (Comparator(Operator.EXACT, 0, None, None, None), False),
460 ],
461 ids=repr,
462)
463def test_is_strict_dep(comp: Comparator, expected: bool):
464 assert _is_strict_dep(comp) == expected