|
4 | 4 | from unittest.mock import MagicMock |
5 | 5 |
|
6 | 6 |
|
7 | | -def test_benchmark_uv_not_installed(cli, monkeypatch): |
| 7 | +def test_benchmark_uv_not_installed_decline(cli, monkeypatch): |
8 | 8 | monkeypatch.setattr(shutil, "which", lambda name: None) |
| 9 | + monkeypatch.setattr("builtins.input", lambda prompt: "n") |
| 10 | + |
| 11 | + calls = [] |
| 12 | + monkeypatch.setattr(subprocess, "run", lambda args, **kw: calls.append(args)) |
| 13 | + |
| 14 | + cli.execute("benchmark", no_color=True) |
| 15 | + assert len(calls) == 0 |
| 16 | + |
| 17 | + |
| 18 | +def test_benchmark_uv_not_installed_install(cli, monkeypatch): |
| 19 | + installed = {"uv": False} |
| 20 | + |
| 21 | + def fake_which(name): |
| 22 | + if name == "uv" and installed["uv"]: |
| 23 | + return "/usr/bin/uv" |
| 24 | + return None |
| 25 | + |
| 26 | + monkeypatch.setattr(shutil, "which", fake_which) |
| 27 | + monkeypatch.setattr("builtins.input", lambda prompt: "y") |
| 28 | + |
| 29 | + calls = [] |
| 30 | + |
| 31 | + def fake_subprocess_run(args, **kwargs): |
| 32 | + calls.append([str(a) for a in args]) |
| 33 | + if args[:2] == ["sh", "/tmp/uv_install.sh"]: |
| 34 | + installed["uv"] = True |
| 35 | + return subprocess.CompletedProcess(args, 0) |
| 36 | + |
| 37 | + monkeypatch.setattr(subprocess, "run", fake_subprocess_run) |
| 38 | + |
| 39 | + from mytonctrl import mytonctrl as mytonctrl_module |
| 40 | + monkeypatch.setattr(mytonctrl_module, "get_service_status", lambda name: True) |
| 41 | + |
9 | 42 | output = cli.execute("benchmark", no_color=True) |
10 | | - assert "uv is not installed" in output |
| 43 | + assert calls[0] == ["curl", "-LsSf", "https://astral.sh/uv/install.sh", "-o", "/tmp/uv_install.sh"] |
| 44 | + assert calls[1] == ["sh", "/tmp/uv_install.sh"] |
11 | 45 |
|
12 | 46 |
|
13 | 47 | def test_benchmark_validator_running(cli, monkeypatch): |
|
0 commit comments