-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtest_cli.py
More file actions
153 lines (128 loc) · 4.13 KB
/
Copy pathtest_cli.py
File metadata and controls
153 lines (128 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import pathlib
from click.testing import CliRunner
from fromager.__main__ import main as fromager
from fromager.commands import commands
def test_migrate_config(
testdata_path: pathlib.Path, tmp_path: pathlib.Path, cli_runner: CliRunner
) -> None:
config027 = testdata_path / "config-0.27"
expected = config027 / "expected"
output = tmp_path / "output"
result = cli_runner.invoke(
fromager,
[
"migrate-config",
"--settings-file",
str(config027 / "settings.yaml"),
"--envs-dir",
str(config027 / "envs"),
"--output-dir",
str(output),
],
)
assert result.exit_code == 0, result.stdout
expected_files = sorted(f.name for f in expected.iterdir())
assert expected_files == sorted(f.name for f in output.iterdir())
for filename in expected_files:
expected_txt = expected.joinpath(filename).read_text()
output_txt = output.joinpath(filename).read_text()
assert output_txt == expected_txt
def test_fromager_version(cli_runner: CliRunner) -> None:
result = cli_runner.invoke(fromager, ["--version"])
assert result.exit_code == 0
assert result.stdout.startswith("fromager, version")
def test_output_dir_hidden_options(cli_runner: CliRunner) -> None:
"""--output-dir is visible in help; old per-directory flags are hidden."""
result = cli_runner.invoke(fromager, ["--help"])
assert "-O, --output-dir" in result.output
lines = result.output.splitlines()
option_lines = [line.strip() for line in lines if line.strip().startswith("-")]
option_names = " ".join(option_lines)
assert "--sdists-repo" not in option_names
assert "--wheels-repo" not in option_names
assert "--work-dir" not in option_names
def test_output_dir_sets_subdirectories(
tmp_path: pathlib.Path, cli_runner: CliRunner
) -> None:
"""Passing -O <dir> creates sdists-repo, wheels-repo, work-dir under it."""
out = tmp_path / "my-output"
out.mkdir()
result = cli_runner.invoke(
fromager,
["-O", str(out), "canonicalize", "some-package"],
)
assert result.exit_code == 0, result.output
assert (out / "sdists-repo").is_dir()
assert (out / "wheels-repo").is_dir()
assert (out / "work-dir").is_dir()
def test_output_dir_overridden_by_explicit_flags(
tmp_path: pathlib.Path, cli_runner: CliRunner
) -> None:
"""Explicit --sdists-repo takes precedence over --output-dir."""
out = tmp_path / "base"
out.mkdir()
result = cli_runner.invoke(
fromager,
[
"-O",
str(out),
"--sdists-repo",
str(tmp_path / "custom-sdists"),
"canonicalize",
"some-package",
],
)
assert result.exit_code == 0, result.output
assert (tmp_path / "custom-sdists").is_dir()
assert (out / "wheels-repo").is_dir()
assert (out / "work-dir").is_dir()
assert not (out / "sdists-repo").exists()
def test_multiple_constraints_files(
tmp_path: pathlib.Path, cli_runner: CliRunner
) -> None:
"""Multiple -c flags are accepted and constraints are merged."""
file1 = tmp_path / "base.txt"
file1.write_text("numpy>=1.24\n")
file2 = tmp_path / "extra.txt"
file2.write_text("numpy<2.0\n")
out = tmp_path / "output"
out.mkdir()
result = cli_runner.invoke(
fromager,
[
"-O",
str(out),
"-c",
str(file1),
"-c",
str(file2),
"canonicalize",
"some-package",
],
)
assert result.exit_code == 0, result.output
KNOWN_COMMANDS: set[str] = {
"bootstrap",
"bootstrap-parallel",
"build",
"build-order",
"build-parallel",
"build-sequence",
"canonicalize",
"download-sequence",
"find-updates",
"graph",
"lint",
"lint-requirements",
"list-overrides",
"list-versions",
"migrate-config",
"minimize",
"package",
"stats",
"step",
"wheel-server",
}
def test_registered_eps() -> None:
registered = {c.name for c in commands}
assert registered == KNOWN_COMMANDS