Upgrade async GPU analysis and workbench UX
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.config import Settings
|
||||
from app.core.errors import AppError
|
||||
from app.services.segmentation_adapter import YoloSegmentationAdapter
|
||||
|
||||
|
||||
def _settings(*, require_cuda: bool, device: str) -> Settings:
|
||||
return Settings(
|
||||
_env_file=None,
|
||||
YOLO_REQUIRE_CUDA=require_cuda,
|
||||
YOLO_DEVICE=device,
|
||||
)
|
||||
|
||||
|
||||
def test_segmentation_runtime_allows_cpu_only_when_cuda_is_not_required() -> None:
|
||||
adapter = YoloSegmentationAdapter(_settings(require_cuda=False, device="cpu"))
|
||||
|
||||
adapter.validate_runtime()
|
||||
|
||||
|
||||
def test_segmentation_runtime_rejects_missing_cuda(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setitem(
|
||||
__import__("sys").modules,
|
||||
"torch",
|
||||
SimpleNamespace(cuda=SimpleNamespace(is_available=lambda: False)),
|
||||
)
|
||||
adapter = YoloSegmentationAdapter(_settings(require_cuda=True, device="cuda:0"))
|
||||
|
||||
with pytest.raises(AppError) as exc_info:
|
||||
adapter.validate_runtime()
|
||||
|
||||
assert exc_info.value.code == "SEGMENTATION_ACCELERATOR_UNAVAILABLE"
|
||||
|
||||
|
||||
def test_segmentation_runtime_rejects_cpu_device_when_cuda_is_required(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setitem(
|
||||
__import__("sys").modules,
|
||||
"torch",
|
||||
SimpleNamespace(cuda=SimpleNamespace(is_available=lambda: True)),
|
||||
)
|
||||
adapter = YoloSegmentationAdapter(_settings(require_cuda=True, device="cpu"))
|
||||
|
||||
with pytest.raises(AppError) as exc_info:
|
||||
adapter.validate_runtime()
|
||||
|
||||
assert exc_info.value.code == "SEGMENTATION_ACCELERATOR_MISCONFIGURED"
|
||||
|
||||
|
||||
def test_segmentation_runtime_accepts_configured_cuda(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setitem(
|
||||
__import__("sys").modules,
|
||||
"torch",
|
||||
SimpleNamespace(cuda=SimpleNamespace(is_available=lambda: True)),
|
||||
)
|
||||
adapter = YoloSegmentationAdapter(_settings(require_cuda=True, device="cuda:0"))
|
||||
|
||||
adapter.validate_runtime()
|
||||
Reference in New Issue
Block a user