Spaces:
Running on Zero
Running on Zero
| import io | |
| import warnings | |
| import wave | |
| import numpy as np | |
| from app import LANGUAGES, iris_markup, mock_mode_enabled | |
| from utils import bytes_to_wav, image_to_bytes, safe_call | |
| def test_image_to_bytes_accepts_numpy(): | |
| image = np.zeros((32, 32, 3), dtype=np.uint8) | |
| result = image_to_bytes(image) | |
| assert result.startswith(b"\xff\xd8") | |
| def test_bytes_to_wav_writes_file(tmp_path): | |
| source = io.BytesIO() | |
| with wave.open(source, "wb") as wav_file: | |
| wav_file.setnchannels(1) | |
| wav_file.setsampwidth(2) | |
| wav_file.setframerate(8_000) | |
| wav_file.writeframes(b"\x00\x00" * 80) | |
| path = bytes_to_wav(source.getvalue()) | |
| with wave.open(path, "rb") as wav_file: | |
| assert wav_file.getframerate() == 8_000 | |
| def test_safe_call_returns_fallback(): | |
| def fail(): | |
| raise RuntimeError("expected") | |
| with warnings.catch_warnings(): | |
| warnings.simplefilter("ignore", UserWarning) | |
| assert safe_call(fail, fallback="fallback") == "fallback" | |
| def test_iris_markup_exposes_state_label(): | |
| markup = iris_markup("seeing", "Seeing") | |
| assert "iris seeing" in markup | |
| assert "Seeing" in markup | |
| def test_supported_languages_include_demo_languages(): | |
| assert LANGUAGES["English"] == "en" | |
| assert LANGUAGES["Chinese"] == "zh" | |
| def test_mock_mode_can_be_forced(monkeypatch): | |
| monkeypatch.setenv("THIRD_EYE_MOCK", "true") | |
| assert mock_mode_enabled() is True | |