mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-09-13 07:21:16 +00:00
fix: pvforecast fails when there is only a single plane (#569)
* fix: pvforecast fails when there is only a single plane * fix: formatting * fix: formatting * fix: add type annotations * add testdata and validation test for single plane * fix: formatting
This commit is contained in:
@@ -19,6 +19,9 @@ from akkudoktoreos.utils.datetimeutil import compare_datetimes, to_datetime, to_
|
||||
DIR_TESTDATA = Path(__file__).absolute().parent.joinpath("testdata")
|
||||
|
||||
FILE_TESTDATA_PV_FORECAST_INPUT_1 = DIR_TESTDATA.joinpath("pv_forecast_input_1.json")
|
||||
FILE_TESTDATA_PV_FORECAST_INPUT_SINGLE_PLANE = DIR_TESTDATA.joinpath(
|
||||
"pv_forecast_input_single_plane.json"
|
||||
)
|
||||
FILE_TESTDATA_PV_FORECAST_RESULT_1 = DIR_TESTDATA.joinpath("pv_forecast_result_1.txt")
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -93,6 +96,16 @@ def sample_forecast_data_raw():
|
||||
return input_data
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_forecast_data_single_plane_raw():
|
||||
"""Fixture that returns raw sample forecast data."""
|
||||
with FILE_TESTDATA_PV_FORECAST_INPUT_SINGLE_PLANE.open(
|
||||
"r", encoding="utf-8", newline=None
|
||||
) as f_in:
|
||||
input_data = f_in.read()
|
||||
return input_data
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_forecast_report():
|
||||
"""Fixture that returns sample forecast data report."""
|
||||
@@ -236,6 +249,20 @@ def test_pvforecast_akkudoktor_validate_data(provider_empty_instance, sample_for
|
||||
# everything worked
|
||||
|
||||
|
||||
def test_pvforecast_akkudoktor_validate_data_single_plane(
|
||||
provider_empty_instance, sample_forecast_data_single_plane_raw
|
||||
):
|
||||
"""Test validation of PV forecast data on sample data with a single plane."""
|
||||
logger.info("The following errors are intentional and part of the test.")
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="Field: meta\nError: Field required\nType: missing\nField: values\nError: Field required\nType: missing\n",
|
||||
):
|
||||
ret = provider_empty_instance._validate_data("{}")
|
||||
data = provider_empty_instance._validate_data(sample_forecast_data_single_plane_raw)
|
||||
# everything worked
|
||||
|
||||
|
||||
@patch("requests.get")
|
||||
def test_pvforecast_akkudoktor_update_with_sample_forecast(
|
||||
mock_get, sample_settings, sample_forecast_data_raw, sample_forecast_start, provider
|
||||
|
Reference in New Issue
Block a user