62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import subprocess
|
|
|
|
import pytest
|
|
|
|
from l4d2host.steam_install import SteamInstaller
|
|
|
|
|
|
def test_windows_then_linux(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
calls: list[list[str]] = []
|
|
|
|
def fake_run_command(cmd, **kwargs):
|
|
del kwargs
|
|
calls.append(list(cmd))
|
|
|
|
monkeypatch.setattr("l4d2host.steam_install.run_command", fake_run_command)
|
|
SteamInstaller().install_or_update()
|
|
assert "windows" in calls[0]
|
|
assert "linux" in calls[1]
|
|
|
|
|
|
def test_fail_fast_on_first_failure(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
calls: list[list[str]] = []
|
|
|
|
def fake_run_command(cmd, **kwargs):
|
|
del kwargs
|
|
calls.append(list(cmd))
|
|
if len(calls) == 1:
|
|
raise subprocess.CalledProcessError(returncode=1, cmd=cmd)
|
|
|
|
monkeypatch.setattr("l4d2host.steam_install.run_command", fake_run_command)
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
SteamInstaller().install_or_update()
|
|
|
|
assert len(calls) == 1
|
|
|
|
|
|
def test_default_install_dir_uses_left4me_root(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("LEFT4ME_ROOT", str(tmp_path))
|
|
calls = []
|
|
monkeypatch.setattr("l4d2host.steam_install.run_command", lambda cmd, **kwargs: calls.append(cmd))
|
|
|
|
SteamInstaller().install_or_update()
|
|
|
|
assert str(tmp_path / "installation") in calls[0]
|
|
|
|
|
|
def test_steam_installer_emits_steps(tmp_path, monkeypatch) -> None:
|
|
from pathlib import Path
|
|
monkeypatch.setenv("LEFT4ME_ROOT", str(tmp_path))
|
|
monkeypatch.setattr("l4d2host.steam_install.run_command", lambda cmd, **kwargs: None)
|
|
|
|
steps: list[str] = []
|
|
|
|
from l4d2host.steam_install import SteamInstaller
|
|
SteamInstaller().install_or_update(on_stdout=steps.append)
|
|
|
|
assert steps == [
|
|
"Step: downloading windows platform payload...",
|
|
"Step: downloading linux platform payload...",
|
|
"Step: installation complete."
|
|
]
|