From e92560064a2fa1c659b4542c7099033f91c3d700 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Fri, 12 Jul 2024 11:40:27 +0200 Subject: [PATCH] fix test --- antarest/core/exceptions.py | 4 ++- .../matrix/test_output_series_matrix.py | 27 +++---------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/antarest/core/exceptions.py b/antarest/core/exceptions.py index 110cf03fb4..157ad3c97e 100644 --- a/antarest/core/exceptions.py +++ b/antarest/core/exceptions.py @@ -10,7 +10,9 @@ class ShouldNotHappenException(Exception): class MustNotModifyOutputException(Exception): - pass + def __init__(self, file_name: str) -> None: + msg = f"Should not modify output file {file_name}" + super().__init__(msg) # ============================================================ diff --git a/tests/storage/repository/filesystem/matrix/test_output_series_matrix.py b/tests/storage/repository/filesystem/matrix/test_output_series_matrix.py index c93f999627..d77bd47ee2 100644 --- a/tests/storage/repository/filesystem/matrix/test_output_series_matrix.py +++ b/tests/storage/repository/filesystem/matrix/test_output_series_matrix.py @@ -4,6 +4,7 @@ import pandas as pd import pytest +from antarest.core.exceptions import MustNotModifyOutputException from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig from antarest.study.storage.rawstudy.model.filesystem.folder_node import ChildNotFoundError from antarest.study.storage.rawstudy.model.filesystem.matrix.head_writer import AreaHeadWriter @@ -84,33 +85,13 @@ def test_load__file_not_found(self, my_study_config: FileStudyTreeConfig) -> Non assert "not found" in err_msg.lower() def test_save(self, my_study_config: FileStudyTreeConfig) -> None: - serializer = Mock() - serializer.build_date.return_value = pd.DataFrame( - { - 0: ["DE", "", "", "", ""], - 1: ["hourly", "", "index", 1, 2], - 2: ["", "", "day", "1", "1"], - 3: ["", "", "month", "JAN", "JAN"], - 4: ["", "", "hourly", "00:00", "01:00"], - } - ) - node = OutputSeriesMatrix( context=Mock(), config=my_study_config, freq=MatrixFrequency.DAILY, - date_serializer=serializer, + date_serializer=Mock(), head_writer=AreaHeadWriter(area="de", data_type="va", freq="hourly"), ) - matrix = pd.DataFrame( - data={ - ("01_solar", "MWh", "EXP"): [27000, 48000], - ("02_wind_on", "MWh", "EXP"): [600, 34400], - }, - index=["01/01", "01/02"], - ) - - node.dump(matrix.to_dict(orient="split")) # type: ignore - actual = my_study_config.path.read_text() - assert actual == MATRIX_DAILY_DATA + with pytest.raises(MustNotModifyOutputException, match="Should not modify output file"): + node.dump(data={})