Spaces:
Running on Zero
Running on Zero
File size: 2,154 Bytes
f7a11cd | 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 | """Unit tests for Iris's pure logic (no models loaded).
Covers the parts that regressed before: voice-command detection (robust to STT
errors like 'modo ao fio'), language choice, and the live-mode 'quiet' check.
Run: pytest -q (from the iris/ folder)
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import app # noqa: E402
def test_command_live_on_including_transcription_errors():
for s in ["modo ao vivo", "Modo ao fio", "modo ao fio.", "ao vivo",
"live mode", "descreva sempre", "modo automatico", "tempo real"]:
assert app.detect_command(s) == "live_on", s
def test_command_live_off():
for s in ["pare", "Pare!", "parar", "desligar", "desliga isso",
"modo manual", "stop", "para de descrever", "chega"]:
assert app.detect_command(s) == "live_off", s
def test_questions_are_not_commands():
for s in ["que cor é a camisa?", "o que tem na mesa?", "quanto tem aqui?",
"lê esse rótulo", "Muito obrigado.", "quem está na sala?", "", "1,2,3"]:
assert app.detect_command(s) is None, s
def test_choose_lang_by_keyword():
assert app.choose_lang("português", "pt") == "pt"
assert app.choose_lang("english", "en") == "en"
assert app.choose_lang("inglês", "pt") == "en" # said the word 'inglês'
assert app.choose_lang("quero falar português", "en") == "pt"
def test_choose_lang_falls_back_to_detected():
assert app.choose_lang("blah", "pt") == "pt"
assert app.choose_lang("blah", "en") == "en"
assert app.choose_lang("", "fr") == "en" # unknown -> default en
def test_is_quiet():
for s in ["NADA", "Nada.", "NONE", "none", "nothing", "", " ", "nenhum"]:
assert app.is_quiet(s) is True, s
for s in ["Há um homem na cadeira.", "A new person entered the room."]:
assert app.is_quiet(s) is False, s
def test_path_helper_accepts_dict_or_object():
assert app._path(None) is None
assert app._path({"path": "/tmp/a.wav"}) == "/tmp/a.wav"
class F:
path = "/tmp/b.wav"
assert app._path(F()) == "/tmp/b.wav"
|