42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
import io
|
|
import sys
|
|
import types
|
|
from contextlib import redirect_stdout
|
|
from unittest.mock import patch
|
|
|
|
from funasr import cli
|
|
|
|
|
|
class DummyAutoModel:
|
|
instances = []
|
|
|
|
def __init__(self, **kwargs):
|
|
self.kwargs = kwargs
|
|
self.instances.append(self)
|
|
|
|
def generate(self, **kwargs):
|
|
return [{"text": "hello"}]
|
|
|
|
|
|
def test_cli_passes_hub_to_auto_model(tmp_path):
|
|
audio_path = tmp_path / "sample.wav"
|
|
audio_path.write_bytes(b"not a real wav")
|
|
fake_torch = types.SimpleNamespace(
|
|
cuda=types.SimpleNamespace(is_available=lambda: False),
|
|
)
|
|
|
|
DummyAutoModel.instances = []
|
|
argv = ["funasr", "--hub", "hf", str(audio_path)]
|
|
|
|
with (
|
|
patch.object(sys, "argv", argv),
|
|
patch.dict(sys.modules, {"torch": fake_torch}),
|
|
patch("funasr.AutoModel", DummyAutoModel),
|
|
redirect_stdout(io.StringIO()) as stdout,
|
|
):
|
|
cli.main()
|
|
|
|
assert DummyAutoModel.instances[0].kwargs["hub"] == "hf"
|
|
assert stdout.getvalue().strip() == "hello"
|
|
|