Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleshot committed May 10, 2024
1 parent b8553c9 commit d1ac7dc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
12 changes: 6 additions & 6 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions witty_pi_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d1ac7dc

Please sign in to comment.