-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
202 lines (165 loc) · 6.69 KB
/
Copy pathtest_cli.py
File metadata and controls
202 lines (165 loc) · 6.69 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
"""Tests for the CLI entry point — --help, --version, unknown commands, typo suggestions."""
from __future__ import annotations
from pathlib import Path
from click.testing import CliRunner
from mlx_stack import __version__
from mlx_stack.cli.main import cli
class TestCLIHelp:
"""Tests for --help output."""
def test_help_exits_zero(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0
def test_help_shows_command_names(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
# All planned commands should appear in help output
for cmd in [
"profile",
"recommend",
"init",
"pull",
"models",
"up",
"down",
"status",
"bench",
"config",
]:
assert cmd in result.output, f"Command '{cmd}' not found in --help output"
def test_help_shows_categories(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert "Setup & Configuration" in result.output
assert "Model Management" in result.output
assert "Stack Lifecycle" in result.output
assert "Diagnostics" in result.output
def test_bare_command_shows_help(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, [])
assert result.exit_code == 0
assert "mlx-stack" in result.output
def test_bare_command_shows_banner(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, [])
assert result.exit_code == 0
# Banner contains box-drawing characters from the ASCII art
assert "███" in result.output
def test_bare_command_shows_version(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, [])
assert __version__ in result.output
def test_bare_command_shows_command_categories(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, [])
assert "Setup & Configuration" in result.output
assert "Model Management" in result.output
assert "Stack Lifecycle" in result.output
assert "Diagnostics" in result.output
def test_bare_command_shows_get_started(
self, clean_mlx_stack_home: Path,
) -> None:
"""When no profile/stack exists, shows 'Get started' nudge."""
runner = CliRunner()
result = runner.invoke(cli, [])
assert result.exit_code == 0
assert "mlx-stack setup" in result.output
class TestCLIVersion:
"""Tests for --version output."""
def test_version_exits_zero(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["--version"])
assert result.exit_code == 0
def test_version_matches_package(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["--version"])
assert __version__ in result.output
def test_version_format(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["--version"])
assert result.output.strip() == f"mlx-stack, version {__version__}"
class TestUnknownCommand:
"""Tests for unknown subcommands and typo suggestions."""
def test_unknown_command_nonzero_exit(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["foobar"])
assert result.exit_code != 0
def test_unknown_command_shows_error(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["foobar"])
assert "foobar" in result.output
def test_unknown_command_no_traceback(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["foobar"])
assert "Traceback" not in result.output
def test_typo_suggests_close_match(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["proflie"])
assert "profile" in result.output
assert "Did you mean" in result.output
def test_typo_suggest_init(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["inti"])
assert "init" in result.output
def test_typo_suggest_status(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["statu"])
assert "status" in result.output
def test_unknown_command_suggests_help(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["foobar"])
assert "--help" in result.output
class TestDataHomeAutoCreation:
"""Tests for data-home gating: only state-writing commands create it."""
def test_bare_command_does_not_create_data_home(
self,
clean_mlx_stack_home: Path,
) -> None:
"""Running bare mlx-stack (help) does NOT create the data directory."""
assert not clean_mlx_stack_home.exists()
runner = CliRunner()
result = runner.invoke(cli, [])
assert result.exit_code == 0
assert not clean_mlx_stack_home.exists()
def test_readonly_subcommand_does_not_create_data_home(
self,
clean_mlx_stack_home: Path,
) -> None:
"""Read-only subcommands do NOT create the data directory."""
assert not clean_mlx_stack_home.exists()
runner = CliRunner()
runner.invoke(cli, ["status"])
assert not clean_mlx_stack_home.exists()
def test_state_writing_subcommand_creates_data_home(
self,
clean_mlx_stack_home: Path,
) -> None:
"""State-writing subcommands (config set) auto-create the data directory."""
assert not clean_mlx_stack_home.exists()
runner = CliRunner()
runner.invoke(cli, ["config", "set", "default-quant", "int4"])
assert clean_mlx_stack_home.exists()
assert clean_mlx_stack_home.is_dir()
def test_existing_data_home_not_affected(
self,
mlx_stack_home: Path,
) -> None:
"""Running CLI when data home already exists doesn't cause errors."""
assert mlx_stack_home.exists()
marker = mlx_stack_home / "test-marker.txt"
marker.write_text("keep me")
runner = CliRunner()
result = runner.invoke(cli, [])
assert result.exit_code == 0
assert mlx_stack_home.exists()
assert marker.read_text() == "keep me"
class TestPlaceholderCommands:
"""Tests for placeholder commands that are not yet implemented."""
def test_config_help(self) -> None:
runner = CliRunner()
result = runner.invoke(cli, ["config", "--help"])
assert result.exit_code == 0
assert "set" in result.output
assert "get" in result.output
assert "list" in result.output
assert "reset" in result.output