refactor: simplify shutil usage in workstation backend tests
This commit is contained in:
@@ -6,12 +6,14 @@ NOT ``getGuestIPAddress`` (which would block 30-60s without VMware Tools).
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from ci_orchestrator.backends import workstation as ws_mod
|
||||
from ci_orchestrator.backends.errors import BackendNotAvailable, BackendOperationFailed
|
||||
from ci_orchestrator.backends.protocol import VmHandle
|
||||
from ci_orchestrator.backends.workstation import WorkstationVmrunBackend
|
||||
@@ -165,8 +167,7 @@ def test_is_running_returns_false_when_absent(
|
||||
# ── _resolve_vmrun(explicit=None) paths ───────────────────────────────────────
|
||||
|
||||
def test_resolve_vmrun_uses_which(monkeypatch: pytest.MonkeyPatch, fake_vmrun: str) -> None:
|
||||
import shutil as _shutil
|
||||
monkeypatch.setattr(_shutil, "which", lambda _name: fake_vmrun)
|
||||
monkeypatch.setattr(shutil, "which", lambda _name: fake_vmrun)
|
||||
backend = WorkstationVmrunBackend() # no explicit path
|
||||
assert backend.vmrun_path == fake_vmrun
|
||||
|
||||
@@ -174,22 +175,16 @@ def test_resolve_vmrun_uses_which(monkeypatch: pytest.MonkeyPatch, fake_vmrun: s
|
||||
def test_resolve_vmrun_uses_default_win_path(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
import shutil as _shutil
|
||||
from ci_orchestrator.backends import workstation as ws_mod
|
||||
|
||||
fake_default = tmp_path / "vmrun.exe"
|
||||
fake_default.write_bytes(b"")
|
||||
monkeypatch.setattr(_shutil, "which", lambda _name: None)
|
||||
monkeypatch.setattr(shutil, "which", lambda _name: None)
|
||||
monkeypatch.setattr(ws_mod, "_DEFAULT_WIN_VMRUN", str(fake_default))
|
||||
backend = WorkstationVmrunBackend()
|
||||
assert backend.vmrun_path == str(fake_default)
|
||||
|
||||
|
||||
def test_resolve_vmrun_raises_when_nothing_found(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import shutil as _shutil
|
||||
from ci_orchestrator.backends import workstation as ws_mod
|
||||
|
||||
monkeypatch.setattr(_shutil, "which", lambda _name: None)
|
||||
monkeypatch.setattr(shutil, "which", lambda _name: None)
|
||||
monkeypatch.setattr(ws_mod, "_DEFAULT_WIN_VMRUN", "/nonexistent/vmrun.exe")
|
||||
with pytest.raises(BackendNotAvailable):
|
||||
WorkstationVmrunBackend()
|
||||
|
||||
Reference in New Issue
Block a user