File size: 1,474 Bytes
2d469d4
 
 
031e3f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d469d4
 
 
 
 
 
 
031e3f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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