From d1ac7dc8a56fbd05f4a7f1c7ee9352483b677f42 Mon Sep 17 00:00:00 2001 From: eagleshot <****@****.com> Date: Fri, 10 May 2024 20:52:56 +0200 Subject: [PATCH] Update tests --- README.md | 2 +- settings.py | 2 +- tests/test_settings.py | 12 ++++++------ witty_pi_4.py | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0e5c9d9..82a3fdf 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ wget -O - https://raw.githubusercontent.com/Eagleshot/GlacierCam/main/updateScri ``` # TODOs ## V1.0 -- [ ] Update settings validation +- [X] Update settings validation - [ ] Move data to seperate class and add tests - [ ] Update Witty Pi 4 firmware - [ ] Finish 3D-printed case diff --git a/settings.py b/settings.py index dad951f..193aa84 100644 --- a/settings.py +++ b/settings.py @@ -22,7 +22,7 @@ class Settings: 'locationOverwrite': {'type': bool, 'default': False}, 'latitude': {'type': float, 'min': -90, 'max': 90, 'default': 0.0}, 'longitude': {'type': float, 'min': -180, 'max': 180, 'default': 0.0}, - # 'logLevel': {'type': str, 'valid_values': ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], 'default': 'INFO'}, + 'logLevel': {'type': str, 'valid_values': ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], 'default': 'INFO'}, 'uploadExtendedDiagnostics': {'type': bool, 'default': False}, 'lowVoltageThreshold': {'type': float, 'min': 0.0, 'max': 30.0, 'default': 0.0}, 'recoveryVoltageThreshold': {'type': float, 'min': 0.0, 'max': 30.0, 'default': 0.0}, diff --git a/tests/test_settings.py b/tests/test_settings.py index 0c07e25..fcd1501 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -55,8 +55,8 @@ def test_setting_and_getting_values(): settings.set('resolution', [1920, 1080]) assert settings.get('resolution') == [1920, 1080] - settings.set('intervalMinutes', 50) - assert settings.get('intervalMinutes') == 50 + settings.set('endTimeHour', 20) + assert settings.get('endTimeHour') == 20 def test_invalid_setting_type(): """Test setting an invalid type for a setting and assert that it is reset to the default value""" @@ -65,14 +65,14 @@ def test_invalid_setting_type(): assert not settings.set('cameraName', 123) assert settings.get('cameraName') == 'GlacierCam' - assert not settings.set('lensPosition', 'invalid') - assert settings.get('lensPosition') == -1.0 + assert not settings.set('enableGPS', 'invalid') + assert settings.get('enableGPS') is False def test_setting_outside_range(): """Test setting a value outside the specified range for a setting and assert that it is reset to the default value""" settings = Settings() - assert not settings.set('intervalMinutes', 0) - assert settings.get('intervalMinutes') == 30 + assert not settings.set('lowVoltageThreshold', 30.1) + assert settings.get('lowVoltageThreshold') == 0.0 assert not settings.set('startTimeHour', 25) assert settings.get('startTimeHour') == 8 diff --git a/witty_pi_4.py b/witty_pi_4.py index 75ae7ae..c519179 100644 --- a/witty_pi_4.py +++ b/witty_pi_4.py @@ -201,8 +201,8 @@ def set_interval_length(self, minutes: int, hours: int = 0) -> None: if self.MAX_DURATION_MINUTES < minutes <= 59: self.interval_length_minutes = minutes - elif minutes == 0 and self.interval_length_hours > 0: - self.interval_length_minutes = 0 + elif self.interval_length_hours > 0 and 0 <= minutes <= 59: + self.interval_length_minutes = minutes else: logging.error("Invalid interval length (minutes): %s", minutes)