88 个测试覆盖配置继承、注册表、GPU 守卫、YOLO 格式解析、数据集、模型形状、 标签模式、聚类原语与 SimCLR 损失,以及 train.py / eval.py / 聚类脚本的入口接线。 含两条回归测试: - PCA 白化放大噪声方向导致簇塌陷(默认 whiten=False 的依据) - classes 写成 data.yaml 路径时 num_classes 必须是类别数而非路径字符串长度 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
27 lines
738 B
Python
27 lines
738 B
Python
"""GPU 守卫:项目禁止在没有 Nvidia GPU 的设备上训练。"""
|
|
|
|
import pytest
|
|
|
|
from utils.device import NoNvidiaGpuError, cuda_devices, require_cuda
|
|
|
|
|
|
def test_require_cuda_matches_hardware():
|
|
devices = cuda_devices()
|
|
if devices:
|
|
assert require_cuda() == devices
|
|
else:
|
|
with pytest.raises(NoNvidiaGpuError):
|
|
require_cuda()
|
|
|
|
|
|
def test_resolve_device_rejects_cuda_without_gpu():
|
|
torch = pytest.importorskip("torch")
|
|
from utils.device import resolve_device
|
|
|
|
if torch.cuda.is_available():
|
|
assert resolve_device("cuda").type == "cuda"
|
|
else:
|
|
with pytest.raises(NoNvidiaGpuError):
|
|
resolve_device("cuda")
|
|
assert resolve_device("cpu").type == "cpu"
|