File size: 1,506 Bytes
9bd3ee0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """Unit tests for cores.onnx — ONNX Runtime model management."""
from __future__ import annotations
from pathlib import Path
import pytest
from cores.onnx import is_onnx_available, get_session, ensure_model, model_path, ONNXModel
class TestONNXAvailability:
def test_returns_bool(self):
assert isinstance(is_onnx_available(), bool)
class TestModelPath:
def test_returns_path_in_models_dir(self, test_settings):
p = model_path("test.onnx", test_settings)
assert isinstance(p, Path)
assert p.name == "test.onnx"
assert "models" in str(p)
def test_creates_models_dir_if_missing(self, test_settings, tmp_path):
test_settings.models_dir = str(tmp_path / "subdir" / "models")
p = model_path("test.onnx", test_settings)
assert Path(test_settings.models_dir).exists()
class TestEnsureModel:
def test_ensure_model_disabled_auto_download(self, test_settings, tmp_path):
test_settings.models_dir = str(tmp_path)
test_settings.models_auto_download = False
with pytest.raises(RuntimeError, match="auto-download is disabled"):
ensure_model("nonexistent.onnx", settings=test_settings)
class TestONNXModel:
"""Tests that don't require onnxruntime to be installed."""
def test_onnx_model_wrapper_init(self):
# ONNXModel wraps a session — we can't test without onnxruntime,
# but we can verify the class exists and is importable
assert ONNXModel is not None
|