diff --git a/tests/ert/unit_tests/storage/test_local_storage.py b/tests/ert/unit_tests/storage/test_local_storage.py index 9a256592d21..b38d7c70ed1 100644 --- a/tests/ert/unit_tests/storage/test_local_storage.py +++ b/tests/ert/unit_tests/storage/test_local_storage.py @@ -3,7 +3,7 @@ import shutil import tempfile from dataclasses import dataclass, field -from datetime import datetime +from datetime import datetime, timedelta from pathlib import Path from typing import Any, Dict, List from unittest.mock import MagicMock, PropertyMock, patch @@ -34,7 +34,7 @@ from ert.config.gen_kw_config import TransformFunctionDefinition from ert.config.general_observation import GenObservation from ert.config.observation_vector import ObsVector -from ert.storage import ErtStorageException, open_storage +from ert.storage import ErtStorageException, LocalEnsemble, open_storage from ert.storage.local_storage import _LOCAL_STORAGE_VERSION from ert.storage.mode import ModeError from ert.storage.realization_storage_state import RealizationStorageState @@ -280,6 +280,45 @@ def test_refresh(tmp_path): assert _ensembles(accessor) == _ensembles(reader) +def test_that_reader_storage_reads_most_recent_response_configs(tmp_path): + reader = open_storage(tmp_path, mode="r") + writer = open_storage(tmp_path, mode="w") + + exp = writer.create_experiment( + responses=[SummaryConfig(keys=["*", "FOPR"], input_files=["not_relevant"])], + name="uniq", + ) + ens: LocalEnsemble = exp.create_ensemble(ensemble_size=10, name="uniq_ens") + + reader.refresh() + read_exp = reader.get_experiment_by_name("uniq") + assert read_exp.id == exp.id + + read_smry_config = read_exp.response_configuration["summary"] + assert read_smry_config.keys == ["*", "FOPR"] + assert not read_smry_config.has_finalized_keys + + smry_data = polars.DataFrame( + { + "response_key": ["FOPR", "FOPR", "WOPR", "WOPR", "FOPT", "FOPT"], + "time": polars.Series( + [datetime.now() + timedelta(days=i) for i in range(6)] + ).dt.cast_time_unit("ms"), + "values": polars.Series( + [0.2, 0.2, 1.0, 1.1, 3.3, 3.3], dtype=polars.Float32 + ), + } + ) + + ens.save_response("summary", smry_data, 0) + assert read_smry_config.keys == ["*", "FOPR"] + assert not read_smry_config.has_finalized_keys + + read_smry_config = read_exp.response_configuration["summary"] + assert read_smry_config.keys == ["FOPR", "FOPT", "WOPR"] + assert read_smry_config.has_finalized_keys + + def test_writing_to_read_only_storage_raises(tmp_path): with open_storage(tmp_path, mode="r") as storage, pytest.raises(ModeError): storage.create_experiment()