21 lines
767 B
Python
21 lines
767 B
Python
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
from cursor_flasher.sound import play_alert
|
|
from cursor_flasher.config import Config
|
|
|
|
|
|
class TestPlayAlert:
|
|
def test_does_nothing_when_disabled(self):
|
|
config = Config(sound_enabled=False)
|
|
play_alert(config)
|
|
|
|
@patch("cursor_flasher.sound.NSSound")
|
|
def test_plays_named_sound(self, mock_nssound):
|
|
mock_sound_obj = MagicMock()
|
|
mock_nssound.soundNamed_.return_value = mock_sound_obj
|
|
config = Config(sound_enabled=True, sound_name="Glass", sound_volume=0.7)
|
|
play_alert(config)
|
|
mock_nssound.soundNamed_.assert_called_once_with("Glass")
|
|
mock_sound_obj.setVolume_.assert_called_once_with(0.7)
|
|
mock_sound_obj.play.assert_called_once()
|