Skip to content

Commit

Permalink
Test that reader storage reads updated response configs
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Nov 12, 2024
1 parent 95dd406 commit 076373b
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tests/ert/unit_tests/storage/test_local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 076373b

Please sign in to comment.