Coverage for rust2rpm/tests/test_cli.py: 100%
9 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-21 18:46 +0100
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-21 18:46 +0100
1import pytest
3from rust2rpm.cli import CliArgs, Options, VendorMode
4from rust2rpm.sysinfo import Target, get_default_target
7@pytest.mark.parametrize(
8 ("args", "expected", "name", "version"),
9 [
10 (
11 [],
12 CliArgs(
13 pkgid=None,
14 path=None,
15 output_directory=None,
16 config_file=None,
17 target=get_default_target(),
18 options=Options(),
19 ),
20 None,
21 None,
22 ),
23 (
24 ["cargo-c@0.9.32"],
25 CliArgs(
26 pkgid="cargo-c@0.9.32",
27 output_directory=None,
28 path=None,
29 config_file=None,
30 target=get_default_target(),
31 options=Options(),
32 ),
33 "cargo-c",
34 "0.9.32",
35 ),
36 (
37 ["rand_core@=0.9.0-alpha.2", "--offline"],
38 CliArgs(
39 pkgid="rand_core@=0.9.0-alpha.2",
40 output_directory=None,
41 path=None,
42 config_file=None,
43 target=get_default_target(),
44 options=Options(offline=True),
45 ),
46 "rand_core",
47 "=0.9.0-alpha.2",
48 ),
49 (
50 ["-s", "syn", "--validate-only"],
51 CliArgs(
52 pkgid="syn",
53 output_directory=None,
54 path=None,
55 config_file=None,
56 target=get_default_target(),
57 options=Options(
58 store_crate=True,
59 validate_only=True,
60 ),
61 ),
62 "syn",
63 None,
64 ),
65 (
66 ["-sp", "syn@1", "--compat", "-r"],
67 CliArgs(
68 pkgid="syn@1",
69 output_directory=None,
70 path=None,
71 config_file=None,
72 target=get_default_target(),
73 options=Options(
74 compat=True,
75 patch=True,
76 reuse_patch=True,
77 store_crate=True,
78 ),
79 ),
80 "syn",
81 "1",
82 ),
83 (
84 ["--target", "epel8", "--rpmautospec", "--no-patch-foreign", "--vendor", "auto"],
85 CliArgs(
86 pkgid=None,
87 output_directory=None,
88 path=None,
89 config_file=None,
90 target=Target.EPEL8,
91 options=Options(
92 patch_foreign=False,
93 rpmautospec=True,
94 vendor=VendorMode.AUTO,
95 ),
96 ),
97 None,
98 None,
99 ),
100 (
101 ["--no-rpmautospec", "--relative-license-paths", "--no-existence-check", "--vendor", "manual"],
102 CliArgs(
103 pkgid=None,
104 output_directory=None,
105 path=None,
106 config_file=None,
107 target=get_default_target(),
108 options=Options(
109 existence_check=False,
110 relative_license_paths=True,
111 rpmautospec=False,
112 vendor=VendorMode.MANUAL,
113 ),
114 ),
115 None,
116 None,
117 ),
118 ],
119 ids=repr,
120)
121def test_cli_args_parse(args: list[str], expected: CliArgs, name: str | None, version: str | None):
122 parsed = CliArgs.parse(args)
124 assert parsed == expected
125 assert parsed.name == name
126 assert parsed.version == version