24 lines
865 B
Python
24 lines
865 B
Python
from unittest.mock import patch, MagicMock
|
|
from void_workers import model
|
|
|
|
|
|
def test_model_returns_singleton(monkeypatch):
|
|
m = MagicMock()
|
|
monkeypatch.setattr(model, "_whisper_model", None)
|
|
with patch("void_workers.model.cuda_available", return_value=False):
|
|
with patch("faster_whisper.WhisperModel", return_value=m):
|
|
a = model.whisper_model()
|
|
b = model.whisper_model()
|
|
assert a is b
|
|
|
|
|
|
def test_transcribe_returns_joined_segments(monkeypatch):
|
|
seg1 = MagicMock(text=" Hello world ")
|
|
seg2 = MagicMock(text=" second line")
|
|
fake_model = MagicMock()
|
|
fake_model.transcribe.return_value = ([seg1, seg2], MagicMock())
|
|
monkeypatch.setattr(model, "_whisper_model", fake_model)
|
|
out = model.whisper_transcribe("/tmp/whatever.opus")
|
|
assert "Hello world" in out
|
|
assert "second line" in out
|