mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-09-13 07:21:16 +00:00
Config: Move lat/long/timezone from prediction to general
This commit is contained in:
@@ -39,49 +39,18 @@ def forecast_providers():
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hours, historic_hours, latitude, longitude, expected_timezone",
|
||||
[
|
||||
(48, 24, 40.7128, -74.0060, "America/New_York"), # Valid latitude/longitude
|
||||
(0, 0, None, None, None), # No location
|
||||
(100, 50, 51.5074, -0.1278, "Europe/London"), # Another valid location
|
||||
],
|
||||
)
|
||||
def test_prediction_common_settings_valid(
|
||||
hours, historic_hours, latitude, longitude, expected_timezone
|
||||
):
|
||||
"""Test valid settings for PredictionCommonSettings."""
|
||||
settings = PredictionCommonSettings(
|
||||
hours=hours,
|
||||
historic_hours=historic_hours,
|
||||
latitude=latitude,
|
||||
longitude=longitude,
|
||||
)
|
||||
assert settings.hours == hours
|
||||
assert settings.historic_hours == historic_hours
|
||||
assert settings.latitude == latitude
|
||||
assert settings.longitude == longitude
|
||||
assert settings.timezone == expected_timezone
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"field_name, invalid_value, expected_error",
|
||||
[
|
||||
("hours", -1, "Input should be greater than or equal to 0"),
|
||||
("historic_hours", -5, "Input should be greater than or equal to 0"),
|
||||
("latitude", -91.0, "Input should be greater than or equal to -90"),
|
||||
("latitude", 91.0, "Input should be less than or equal to 90"),
|
||||
("longitude", -181.0, "Input should be greater than or equal to -180"),
|
||||
("longitude", 181.0, "Input should be less than or equal to 180"),
|
||||
],
|
||||
)
|
||||
def test_prediction_common_settings_invalid(field_name, invalid_value, expected_error):
|
||||
def test_prediction_common_settings_invalid(field_name, invalid_value, expected_error, config_eos):
|
||||
"""Test invalid settings for PredictionCommonSettings."""
|
||||
valid_data = {
|
||||
"hours": 48,
|
||||
"historic_hours": 24,
|
||||
"latitude": 40.7128,
|
||||
"longitude": -74.0060,
|
||||
}
|
||||
assert PredictionCommonSettings(**valid_data) is not None
|
||||
valid_data[field_name] = invalid_value
|
||||
@@ -90,31 +59,6 @@ def test_prediction_common_settings_invalid(field_name, invalid_value, expected_
|
||||
PredictionCommonSettings(**valid_data)
|
||||
|
||||
|
||||
def test_prediction_common_settings_no_location():
|
||||
"""Test that timezone is None when latitude and longitude are not provided."""
|
||||
settings = PredictionCommonSettings(hours=48, historic_hours=24, latitude=None, longitude=None)
|
||||
assert settings.timezone is None
|
||||
|
||||
|
||||
def test_prediction_common_settings_with_location():
|
||||
"""Test that timezone is correctly computed when latitude and longitude are provided."""
|
||||
settings = PredictionCommonSettings(
|
||||
hours=48, historic_hours=24, latitude=34.0522, longitude=-118.2437
|
||||
)
|
||||
assert settings.timezone == "America/Los_Angeles"
|
||||
|
||||
|
||||
def test_prediction_common_settings_timezone_none_when_coordinates_missing():
|
||||
"""Test that timezone is None when latitude or longitude is missing."""
|
||||
config_no_latitude = PredictionCommonSettings(latitude=None, longitude=-74.0060)
|
||||
config_no_longitude = PredictionCommonSettings(latitude=40.7128, longitude=None)
|
||||
config_no_coords = PredictionCommonSettings(latitude=None, longitude=None)
|
||||
|
||||
assert config_no_latitude.timezone is None
|
||||
assert config_no_longitude.timezone is None
|
||||
assert config_no_coords.timezone is None
|
||||
|
||||
|
||||
def test_initialization(prediction, forecast_providers):
|
||||
"""Test that Prediction is initialized with the correct providers in sequence."""
|
||||
assert isinstance(prediction, Prediction)
|
||||
|
Reference in New Issue
Block a user