Skip to content

Commit

Permalink
Test empty gen_kw in plotapi
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Oct 11, 2024
1 parent e5934eb commit 7d8d5df
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/ert/unit_tests/gui/tools/plot/test_plot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import pandas as pd
import polars
import pytest
import xarray as xr
from pandas.testing import assert_frame_equal
from starlette.testclient import TestClient

from ert.config import SummaryConfig
from ert.config import GenKwConfig, SummaryConfig
from ert.dark_storage import enkf
from ert.dark_storage.app import app
from ert.gui.tools.plot.plot_api import PlotApi, PlotApiKeyDefinition
Expand Down Expand Up @@ -236,3 +237,49 @@ def test_plot_api_handles_urlescape(tmp_path, monkeypatch):
enkf._storage.close()
enkf._storage = None
gc.collect()


def test_plot_api_handles_empty_gen_kw(tmp_path, monkeypatch):
with open_storage(tmp_path / "storage", mode="w") as storage:
monkeypatch.setenv("ERT_STORAGE_NO_TOKEN", "yup")
monkeypatch.setenv("ERT_STORAGE_ENS_PATH", storage.path)
api = PlotApi()
key = "gen_kw"
name = "<poro>"
experiment = storage.create_experiment(
parameters=[
GenKwConfig(
name=key,
forward_init=False,
update=False,
template_file=None,
output_file=None,
transform_function_definitions=[],
),
],
responses=[],
observations={},
)
ensemble = storage.create_ensemble(experiment.id, ensemble_size=10)
assert api.data_for_key(str(ensemble.id), key).empty
ensemble.save_parameters(
key,
1,
xr.Dataset(
{
"values": ("names", [1.0]),
"transformed_values": ("names", [1.0]),
"names": [name],
}
),
)
assert api.data_for_key(str(ensemble.id), key + ":" + name).to_csv() == dedent(
"""\
Realization,0
1,1.0
"""
)
if enkf._storage is not None:
enkf._storage.close()
enkf._storage = None
gc.collect()

0 comments on commit 7d8d5df

Please sign in to comment.