from unittest.mock import Mock

import pytest

from fenrirscreenreader.core.soundDriver import sound_driver
from fenrirscreenreader.soundDriver import gstreamerDriver


@pytest.mark.unit
def test_base_sound_driver_shutdown_clears_initialized_flag():
    driver = sound_driver()
    driver.initialize({})

    driver.shutdown()

    assert driver._initialized is False


@pytest.mark.unit
def test_gstreamer_driver_unavailable_logs_without_crashing(monkeypatch):
    monkeypatch.setattr(gstreamerDriver, "_gstreamerAvailable", False)
    monkeypatch.setattr(gstreamerDriver, "_availableError", "missing", raising=False)
    debug_manager = Mock(write_debug_out=Mock())
    driver = gstreamerDriver.driver()

    driver.initialize({"runtime": {"DebugManager": debug_manager}})

    debug_manager.write_debug_out.assert_called()
    assert driver._initialized is False
