from domin8 import resources
def test_detect_cpu_count():
n = resources.detect_cpu_count()
assert isinstance(n, int) and n >= 1
def test_detect_gpus_no_gpu(monkeypatch):
# Ensure no torch and no nvidia-smi
monkeypatch.setattr(resources, 'shutil', resources.shutil)
# Simulate missing uv and tools
res = resources.detect_gpus()
assert res.device_count >= 0
def test_ensure_ml_deps_install_called(monkeypatch, tmp_path):
# Simulate presence of uv command
monkeypatch.setattr(resources, 'shutil', resources.shutil)
monkeypatch.setattr(resources.shutil, 'which', lambda x: '/usr/bin/uv')
calls = []
def fake_run(cmd, check=True, **kwargs):
calls.append(cmd)
class R:
returncode = 0
return R()
monkeypatch.setattr(resources.subprocess, 'run', fake_run)
ok = resources.ensure_ml_deps_installed('torch')
assert ok
# Expect uv add --upgrade torch was called
assert any('add' in c and 'torch' in c for c in calls)