-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure keys can contain "/" #8818
Merged
eivindjahren
merged 5 commits into
equinor:main
from
eivindjahren:stateful_dark_storage_test
Oct 11, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86a8105
Fix bug where dark storage didn't return empty
eivindjahren df1cb57
Fix incorrect assertion in stateful storage test
eivindjahren 88bf60e
escape keys in plot api
eivindjahren 4ce5be5
Add stateful dark storage test
eivindjahren d1363a3
Test empty gen_kw in plotapi
eivindjahren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
tests/ert/unit_tests/dark_storage/test_dark_storage_state.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import gc | ||
import io | ||
import os | ||
from urllib.parse import quote | ||
from uuid import UUID | ||
|
||
import hypothesis.strategies as st | ||
import pandas as pd | ||
import polars | ||
import pytest | ||
from hypothesis import assume | ||
from hypothesis.stateful import rule | ||
from starlette.testclient import TestClient | ||
|
||
from ert.dark_storage import enkf | ||
from ert.dark_storage.app import app | ||
from tests.ert.unit_tests.storage.test_local_storage import StatefulStorageTest | ||
|
||
|
||
def escape(s): | ||
return quote(quote(quote(s, safe=""))) | ||
|
||
|
||
class DarkStorageStateTest(StatefulStorageTest): | ||
def __init__(self): | ||
super().__init__() | ||
self.prev_no_token = os.environ.get("ERT_STORAGE_NO_TOKEN") | ||
self.prev_ens_path = os.environ.get("ERT_STORAGE_ENS_PATH") | ||
os.environ["ERT_STORAGE_NO_TOKEN"] = "yup" | ||
os.environ["ERT_STORAGE_ENS_PATH"] = str(self.storage.path) | ||
self.client = TestClient(app) | ||
|
||
@rule() | ||
def get_experiments_through_client(self): | ||
self.client.get("/updates/storage") | ||
response = self.client.get("/experiments") | ||
experiment_records = response.json() | ||
assert len(experiment_records) == len(list(self.storage.experiments)) | ||
for record in experiment_records: | ||
storage_experiment = self.storage.get_experiment(UUID(record["id"])) | ||
assert {UUID(i) for i in record["ensemble_ids"]} == { | ||
ens.id for ens in storage_experiment.ensembles | ||
} | ||
|
||
@rule(model_experiment=StatefulStorageTest.experiments) | ||
def get_observations_through_client(self, model_experiment): | ||
response = self.client.get(f"/experiments/{model_experiment.uuid}/observations") | ||
assert {r["name"] for r in response.json()} == { | ||
key | ||
for _, ds in model_experiment.observations.items() | ||
for key in ds["observation_key"] | ||
} | ||
|
||
@rule(model_experiment=StatefulStorageTest.experiments) | ||
def get_ensembles_through_client(self, model_experiment): | ||
response = self.client.get(f"/experiments/{model_experiment.uuid}/ensembles") | ||
assert {r["id"] for r in response.json()} == { | ||
str(uuid) for uuid in model_experiment.ensembles | ||
} | ||
|
||
@rule(model_ensemble=StatefulStorageTest.ensembles) | ||
def get_responses_through_client(self, model_ensemble): | ||
response = self.client.get(f"/ensembles/{model_ensemble.uuid}/responses") | ||
response_names = { | ||
k | ||
for r in model_ensemble.response_values.values() | ||
for k in r["response_key"] | ||
} | ||
assert set(response.json().keys()) == response_names | ||
|
||
@rule(model_ensemble=StatefulStorageTest.ensembles, data=st.data()) | ||
def get_response_csv_through_client(self, model_ensemble, data): | ||
assume(model_ensemble.response_values) | ||
response_name, response_key = data.draw( | ||
st.sampled_from( | ||
[ | ||
(response_name, response_key) | ||
for response_name, r in model_ensemble.response_values.items() | ||
for response_key in r["response_key"] | ||
] | ||
) | ||
) | ||
df = pd.read_parquet( | ||
io.BytesIO( | ||
self.client.get( | ||
f"/ensembles/{model_ensemble.uuid}/records/{escape(response_key)}", | ||
headers={"accept": "application/x-parquet"}, | ||
).content | ||
) | ||
) | ||
assert {dt[:10] for dt in df.columns} == { | ||
str(dt)[:10] | ||
for dt in model_ensemble.response_values[response_name].filter( | ||
polars.col("response_key") == response_key | ||
)["time"] | ||
} | ||
|
||
def teardown(self): | ||
super().teardown() | ||
if enkf._storage is not None: | ||
enkf._storage.close() | ||
enkf._storage = None | ||
gc.collect() | ||
if self.prev_no_token is not None: | ||
os.environ["ERT_STORAGE_NO_TOKEN"] = self.prev_no_token | ||
else: | ||
del os.environ["ERT_STORAGE_NO_TOKEN"] | ||
if self.prev_ens_path is not None: | ||
os.environ["ERT_STORAGE_ENS_PATH"] = self.prev_ens_path | ||
else: | ||
del os.environ["ERT_STORAGE_ENS_PATH"] | ||
|
||
|
||
TestDarkStorage = pytest.mark.integration_test(DarkStorageStateTest.TestCase) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check that this is not zero also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be empty if we haven't initialized anything in storage yet.