Skip to content

Commit

Permalink
i"ll get it right one day
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmacdonald80 committed May 12, 2024
1 parent 597eb50 commit 6296c48
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/test_alarm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from phue import Bridge
from unittest.mock import patch, MagicMock, Mock, call
from unittest.mock import patch, MagicMock, Mock, call, ANY
from src.alarm import set_volume_for_all_sinks, set_lights, log_to_journal

@pytest.fixture
Expand Down Expand Up @@ -48,6 +48,7 @@ def test_set_lights_on_success(mock_bridge, mock_log_to_journal):
set_lights(mock_bridge, True) # Test setting lights on
mock_bridge.set_light.assert_called_once_with(['Lamp', 'FarWall', 'NearWall'], {'transitiontime': 3000, 'on': True, 'bri': 254})
mock_log_to_journal.assert_called_with("Lights on at ...", level='info')
mock_log_to_journal.assert_has_calls([call(ANY, level='info')])

def test_set_lights_off_success(mock_bridge, mock_log_to_journal):
# mock_bridge.set_light.return_value = None # Assume success doesn't return anything
Expand All @@ -56,8 +57,9 @@ def test_set_lights_off_success(mock_bridge, mock_log_to_journal):
mock_log_to_journal.assert_called_with("Lights off at ...", level='info')

def test_set_lights_failure(mock_bridge, mock_log_to_journal):
mock_bridge.set_light.side_effect = Exception("Connection error0")
expected_exception = Exception("Connection error0")
mock_bridge.set_light.side_effect = expected_exception
set_lights(mock_bridge, True) # Attempt to turn lights on
mock_log_to_journal.assert_called_with("Failed to control lights.", level='error', exception=Mock())
mock_log_to_journal.assert_called_with("Failed to control lights.", level='error', exception=expected_exception)


0 comments on commit 6296c48

Please sign in to comment.