-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_model_loading.py
More file actions
85 lines (65 loc) · 2.81 KB
/
Copy pathtest_model_loading.py
File metadata and controls
85 lines (65 loc) · 2.81 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Unit tests for model loading and error handling.
"""
import pytest
import sys
from unittest.mock import Mock, patch
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent))
def test_nvidia_model_without_nemo():
"""Test that NVIDIA models fail gracefully without nemo-toolkit installed."""
from models.factory import ModelFactory
# Mock the nemo import to fail
with patch.dict('sys.modules', {'nemo.collections.asr': None}):
with pytest.raises(ImportError) as exc_info:
model = ModelFactory.get_model(
model_type="nvidia/parakeet-tdt-0.6b-v3",
device=None,
verbose=False
)
# Check that error message is helpful
assert "nemo-toolkit" in str(exc_info.value).lower()
assert "reinstall" in str(exc_info.value).lower() or "install" in str(exc_info.value).lower()
def test_mlx_model_loads():
"""Test that MLX models can be created (not loaded, just instantiated)."""
from models.factory import ModelFactory
import platform
# Only run on Apple Silicon
if sys.platform != "darwin" or platform.machine() != "arm64":
pytest.skip("MLX only supported on Apple Silicon")
# This should not raise
model = ModelFactory.get_model(
model_type="mlx-community/parakeet-tdt-0.6b-v3",
device=None,
verbose=False
)
assert model is not None
assert hasattr(model, 'load_model')
def test_model_alias_resolution():
"""Test that model aliases resolve correctly."""
from models.factory import ModelFactory
from state import NVIDIA_PARAKEET_V3
# Test alias resolution to canonical aliases
assert ModelFactory.resolve_model_alias("parakeet") == "parakeet"
assert ModelFactory.resolve_model_alias("parakeet-v3") == "parakeet-v3"
assert ModelFactory.resolve_model_alias("parakeet-v3-mlx") == "parakeet-v3-mlx"
# Test that a repo id resolves back to the canonical alias
assert ModelFactory.resolve_model_alias(NVIDIA_PARAKEET_V3) == "parakeet-v3"
def test_get_model_raises_on_import_error():
"""Test that get_model() raises ModelLoadError when dependencies are missing."""
import state
from model_loader import get_model, ModelLoadError
# Set up state for a NVIDIA model
state.model_type = "nvidia/parakeet-tdt-0.6b-v3"
state.device = None
state.DEBUG_MODE = False
state.stt_model = None
# Mock the nemo import to fail
with patch('models.factory.ModelFactory.get_model', side_effect=ImportError("nemo-toolkit not found")):
with pytest.raises(ModelLoadError) as exc_info:
get_model()
# Check that error message is passed through
assert "nemo-toolkit" in str(exc_info.value).lower()
if __name__ == "__main__":
pytest.main([__file__, "-v"])