Some checks failed
Make distro packages the single source of truth for GTK/X11 Python bindings instead of advertising them as wheel-managed runtime dependencies. Update the uv, CI, and packaging workflows to use system site packages, regenerate uv.lock, and keep portable and Arch metadata aligned with that contract. Pull runtime policy, audio probing, and page builders out of config_ui.py so the settings window becomes a coordinator instead of a single large mixed-concern module. Rename the config serialization and logging helpers, and stop startup logging from exposing raw vocabulary entries or custom model paths. Remove stale helper aliases and add regression coverage for safe startup logging, packaging metadata and module drift, portable requirements, and the extracted audio helper behavior. Validated with uv lock, python3 -m compileall -q src tests, python3 -m unittest discover -s tests -p 'test_*.py', make build, and make package-arch.
53 lines
2 KiB
Python
53 lines
2 KiB
Python
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SRC = ROOT / "src"
|
|
if str(SRC) not in sys.path:
|
|
sys.path.insert(0, str(SRC))
|
|
|
|
from config_ui_audio import AudioSettingsService
|
|
|
|
|
|
class AudioSettingsServiceTests(unittest.TestCase):
|
|
def test_microphone_test_reports_success_when_audio_is_captured(self):
|
|
service = AudioSettingsService()
|
|
with patch("config_ui_audio.start_recording", return_value=("stream", "record")), patch(
|
|
"config_ui_audio.stop_recording",
|
|
return_value=SimpleNamespace(size=4),
|
|
), patch("config_ui_audio.time.sleep") as sleep_mock:
|
|
result = service.test_microphone("USB Mic", duration_sec=0.0)
|
|
|
|
self.assertTrue(result.ok)
|
|
self.assertEqual(result.message, "Microphone test successful.")
|
|
sleep_mock.assert_called_once_with(0.0)
|
|
|
|
def test_microphone_test_reports_empty_capture(self):
|
|
service = AudioSettingsService()
|
|
with patch("config_ui_audio.start_recording", return_value=("stream", "record")), patch(
|
|
"config_ui_audio.stop_recording",
|
|
return_value=SimpleNamespace(size=0),
|
|
), patch("config_ui_audio.time.sleep"):
|
|
result = service.test_microphone("USB Mic", duration_sec=0.0)
|
|
|
|
self.assertFalse(result.ok)
|
|
self.assertEqual(result.message, "No audio captured. Try another device.")
|
|
|
|
def test_microphone_test_surfaces_recording_errors(self):
|
|
service = AudioSettingsService()
|
|
with patch(
|
|
"config_ui_audio.start_recording",
|
|
side_effect=RuntimeError("device missing"),
|
|
), patch("config_ui_audio.time.sleep") as sleep_mock:
|
|
result = service.test_microphone("USB Mic", duration_sec=0.0)
|
|
|
|
self.assertFalse(result.ok)
|
|
self.assertEqual(result.message, "Microphone test failed: device missing")
|
|
sleep_mock.assert_not_called()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|