| """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): |
| |
| |
| assert ONNXModel is not None |
|
|