mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-08 04:08:06 +00:00
test: real schedule/dim coverage for DisplayController; fix two vacuous schedule tests
New test_display_controller_schedule.py drives _check_schedule and _check_dim_schedule on a bare controller stub: same-day and midnight-crossing windows with inclusive boundaries, global vs per-day vs legacy-inferred modes (and dim's global-only default — no legacy inference), per-day disabled days, invalid %H:%M fallbacks, unknown timezone -> UTC, dim_brightness default 30, inactive-display short circuit, and the _was_display_active/_was_dimmed transition flags. test_display_controller.py's test_schedule_disabled and test_active_hours patched config_service.get_config — which _check_schedule never reads — so both asserted the init-default value and could not fail. Rewritten on the test_inactive_hours pattern (inject controller.config['schedule'], reset the minute gate, flip the flag to the opposite state first so the assertion has teeth). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NohXi78cwsAKtN1sCfxjUh
This commit is contained in:
@@ -338,31 +338,48 @@ class TestDisplayControllerSchedule:
|
||||
"""Test schedule management."""
|
||||
|
||||
def test_schedule_disabled(self, test_display_controller):
|
||||
"""Test when schedule is disabled."""
|
||||
"""schedule.enabled=False keeps the display active even outside the
|
||||
configured window. (This test used to patch config_service, which
|
||||
_check_schedule never reads — it asserted the init default.)"""
|
||||
controller = test_display_controller
|
||||
schedule_config = {"schedule": {"enabled": False}}
|
||||
with patch.object(controller.config_service, 'get_config', return_value=schedule_config):
|
||||
controller.config['schedule'] = {
|
||||
"enabled": False,
|
||||
"start_time": "09:00",
|
||||
"end_time": "17:00",
|
||||
}
|
||||
controller._schedule_checked_minute = None
|
||||
controller._tz = None
|
||||
controller.is_display_active = False # prove the method flips it back
|
||||
|
||||
with patch('src.display_controller.datetime') as mock_datetime:
|
||||
mock_datetime.now.return_value.strftime.return_value.lower.return_value = "monday"
|
||||
mock_datetime.now.return_value.time.return_value = datetime.strptime("20:00", "%H:%M").time()
|
||||
mock_datetime.strptime = datetime.strptime
|
||||
|
||||
controller._check_schedule()
|
||||
assert controller.is_display_active is True
|
||||
|
||||
def test_active_hours(self, test_display_controller):
|
||||
"""Test active hours check."""
|
||||
"""A time inside the window activates the display. (This test used
|
||||
to patch config_service, which _check_schedule never reads — it
|
||||
asserted the init default.)"""
|
||||
controller = test_display_controller
|
||||
controller.config['schedule'] = {
|
||||
"enabled": True,
|
||||
"start_time": "09:00",
|
||||
"end_time": "17:00",
|
||||
}
|
||||
controller._schedule_checked_minute = None
|
||||
controller._tz = None
|
||||
controller.is_display_active = False # prove the method flips it on
|
||||
|
||||
with patch('src.display_controller.datetime') as mock_datetime:
|
||||
mock_datetime.now.return_value.strftime.return_value.lower.return_value = "monday"
|
||||
mock_datetime.now.return_value.time.return_value = datetime.strptime("12:00", "%H:%M").time()
|
||||
mock_datetime.strptime = datetime.strptime
|
||||
|
||||
schedule_config = {
|
||||
"schedule": {
|
||||
"enabled": True,
|
||||
"start_time": "09:00",
|
||||
"end_time": "17:00"
|
||||
}
|
||||
}
|
||||
with patch.object(controller.config_service, 'get_config', return_value=schedule_config):
|
||||
controller._check_schedule()
|
||||
assert controller.is_display_active is True
|
||||
controller._check_schedule()
|
||||
assert controller.is_display_active is True
|
||||
|
||||
def test_inactive_hours(self, test_display_controller):
|
||||
"""Test inactive hours check."""
|
||||
|
||||
Reference in New Issue
Block a user