Reasonable defaults, isolate tests, EOS_LOGGING_LEVEL, EOS_CONFIG_DIR

* Add EOS_CONFIG_DIR to set config dir (relative path to EOS_DIR or
   absolute path).
    - config_folder_path read-only
    - config_file_path read-only
 * Default values to support app start with empty config:
    - latitude/longitude (Berlin)
    - optimization_ev_available_charge_rates_percent (null, so model
      default value is used)
    - Enable Akkudoktor electricity price forecast (docker-compose).
 * Fix some endpoints (empty data, remove unused params, fix types).
 * cacheutil: Use cache dir. Closes #240
 * Support EOS_LOGGING_LEVEL environment variable to set log level.
 * tests: All tests use separate temporary config
    - Add pytest switch --check-config-side-effect to check user
      config file existence after each test. Will also fail if user config
      existed before test execution (but will only check after the test has
      run).
      Enable flag in github workflow.
    - Globally mock platformdirs in config module. Now no longer required
      to patch individually.
      Function calls to config instance (e.g. merge_settings_from_dict)
      were unaffected previously.
 * Set Berlin as default location (default config/docker-compose).
This commit is contained in:
Dominique Lasserre
2024-12-30 13:41:39 +01:00
committed by GitHub
parent 267a9bf427
commit 75987db9e1
29 changed files with 373 additions and 375 deletions

View File

@@ -9,7 +9,6 @@ import pvlib
import pytest
from bs4 import BeautifulSoup
from akkudoktoreos.config.config import get_config
from akkudoktoreos.core.ems import get_ems
from akkudoktoreos.prediction.weatherclearoutside import WeatherClearOutside
from akkudoktoreos.utils.cacheutil import CacheFileStore
@@ -20,12 +19,9 @@ DIR_TESTDATA = Path(__file__).absolute().parent.joinpath("testdata")
FILE_TESTDATA_WEATHERCLEAROUTSIDE_1_HTML = DIR_TESTDATA.joinpath("weatherforecast_clearout_1.html")
FILE_TESTDATA_WEATHERCLEAROUTSIDE_1_DATA = DIR_TESTDATA.joinpath("weatherforecast_clearout_1.json")
config_eos = get_config()
ems_eos = get_ems()
@pytest.fixture
def weather_provider():
def weather_provider(config_eos):
"""Fixture to create a WeatherProvider instance."""
settings = {
"weather_provider": "ClearOutside",
@@ -70,16 +66,16 @@ def test_singleton_instance(weather_provider):
assert weather_provider is another_instance
def test_invalid_provider(weather_provider):
def test_invalid_provider(weather_provider, config_eos):
"""Test requesting an unsupported weather_provider."""
settings = {
"weather_provider": "<invalid>",
}
config_eos.merge_settings_from_dict(settings)
assert weather_provider.enabled() == False
assert not weather_provider.enabled()
def test_invalid_coordinates(weather_provider):
def test_invalid_coordinates(weather_provider, config_eos):
"""Test invalid coordinates raise ValueError."""
settings = {
"weather_provider": "ClearOutside",
@@ -118,7 +114,7 @@ def test_irridiance_estimate_from_cloud_cover(weather_provider):
@patch("requests.get")
def test_request_forecast(mock_get, weather_provider, sample_clearout_1_html):
def test_request_forecast(mock_get, weather_provider, sample_clearout_1_html, config_eos):
"""Test fetching forecast from ClearOutside."""
# Mock response object
mock_response = Mock()
@@ -149,6 +145,7 @@ def test_update_data(mock_get, weather_provider, sample_clearout_1_html, sample_
expected_keep = to_datetime("2024-10-24 00:00:00", in_timezone="Europe/Berlin")
# Call the method
ems_eos = get_ems()
ems_eos.set_start_datetime(expected_start)
weather_provider.update_data()