| """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 |
|
|
|
|
| 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" |
| 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" |
|
|
|
|
| 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" |
|
|