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