view dictation/config_test.py @ 275:78699f810817

Add Qwen3-VL and WebRTC dictation services Add Bazel targets for the CUDA-backed Qwen3-VL server and a local WebRTC faster-whisper dictation service. Co-authored-by: Copilot <[email protected]> Copilot-Session: e3d8cb06-6c95-4ae0-9757-651d3796ab00
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 10:58:47 -0700
parents
children 49e9e591c9bb
line wrap: on
line source

import os
from pathlib import Path
import unittest
from unittest.mock import patch

from dictation.config import DictationConfig


class DictationConfigTest(unittest.TestCase):
    def test_defaults_are_local_and_bounded(self):
        with patch.dict(os.environ, {}, clear=True):
            config = DictationConfig.from_environment()
        self.assertEqual(config.host, "127.0.0.1")
        self.assertEqual(config.port, 8090)
        self.assertEqual(config.max_sessions, 1)
        self.assertEqual(config.compute_type, "int8_float16")
        self.assertTrue(str(config.model_dir).endswith("faster-whisper-small"))

    def test_rejects_invalid_session_limit(self):
        with patch.dict(
            os.environ,
            {"DICTATION_MAX_SESSIONS": "0"},
            clear=True,
        ):
            with self.assertRaisesRegex(ValueError, "between 1 and 8"):
                DictationConfig.from_environment()

    def test_accepts_model_override(self):
        with patch.dict(
            os.environ,
            {"DICTATION_MODEL_DIR": "/tmp/dictation-model"},
            clear=True,
        ):
            config = DictationConfig.from_environment()
        self.assertEqual(config.model_dir, Path("/tmp/dictation-model"))


if __name__ == "__main__":
    unittest.main()