Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Oct 30, 2024
1 parent 203dc18 commit 83b303d
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 42 deletions.
157 changes: 116 additions & 41 deletions tests/unit_tests/gui/tools/plot/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,48 +90,100 @@ def mocked_requests_get(*args, **kwargs):
"/ensembles/ens_id_2": {"name": ".ensemble_2", "experiment_name": "experiment"},
"/ensembles/ens_id_3": {"name": "default_0", "experiment_name": "experiment"},
"/ensembles/ens_id_4": {"name": "default_1", "experiment_name": "experiment"},
}
observations = {
"/ensembles/ens_id_3/records/WOPR:OP1/observations": {
"name": "WOPR:OP1",
"errors": [0.05, 0.07],
"values": [0.1, 0.7],
"x_axis": ["2010-03-31T00:00:00", "2010-12-26T00:00:00"],
},
"/ensembles/ens_id_4/records/WOPR:OP1/observations": {
"name": "WOPR:OP1",
"errors": [0.05, 0.07],
"values": [0.1, 0.7],
"x_axis": ["2010-03-31T00:00:00", "2010-12-26T00:00:00"],
},
"/ensembles/ens_id_3/records/SNAKE_OIL_WPR_DIFF@199/observations": {
"name": "SNAKE_OIL_WPR_DIFF",
"errors": [0.05, 0.07, 0.05],
"values": [0.1, 0.7, 0.5],
"x_axis": [
"2010-03-31T00:00:00",
"2010-12-26T00:00:00",
"2011-12-21T00:00:00",
],
},
"/ensembles/ens_id_4/records/SNAKE_OIL_WPR_DIFF@199/observations": {
"name": "WOPR:OP1",
"errors": [0.05, 0.07, 0.05],
"values": [0.1, 0.7, 0.5],
"x_axis": [
"2010-03-31T00:00:00",
"2010-12-26T00:00:00",
"2011-12-21T00:00:00",
],
},
"/ensembles/ens_id_3/records/FOPR/observations": {
"name": "FOPR",
"errors": [0.05, 0.07],
"values": [0.1, 0.7],
"x_axis": ["2010-03-31T00:00:00", "2010-12-26T00:00:00"],
"/ensembles/ens_id_5": {
"name": "default_manyobs",
"experiment_name": "experiment",
},
}

observations = {
"/ensembles/ens_id_5/records/WOPR:OP1/observations": [
{
"name": "WOPR_OP1_108",
"errors": [0.07500000298023224],
"values": [0.30000001192092896],
"x_axis": ["2012-12-15T00:00:00"],
},
{
"name": "WOPR_OP1_144",
"errors": [0.03500000014901161],
"values": [0.20000000298023224],
"x_axis": ["2013-12-10T00:00:00"],
},
{
"name": "WOPR_OP1_190",
"errors": [0.009999999776482582],
"values": [0.014999999664723873],
"x_axis": ["2015-03-15T00:00:00"],
},
{
"name": "WOPR_OP1_36",
"errors": [0.07000000029802322],
"values": [0.699999988079071],
"x_axis": ["2010-12-26T00:00:00"],
},
{
"name": "WOPR_OP1_72",
"errors": [0.05000000074505806],
"values": [0.5],
"x_axis": ["2011-12-21T00:00:00"],
},
{
"name": "WOPR_OP1_9",
"errors": [0.05000000074505806],
"values": [0.10000000149011612],
"x_axis": ["2010-03-31T00:00:00"],
},
],
"/ensembles/ens_id_3/records/WOPR:OP1/observations": [
{
"name": "WOPR:OP1",
"errors": [0.05, 0.07],
"values": [0.1, 0.7],
"x_axis": ["2010-03-31T00:00:00", "2010-12-26T00:00:00"],
}
],
"/ensembles/ens_id_4/records/WOPR:OP1/observations": [
{
"name": "WOPR:OP1",
"errors": [0.05, 0.07],
"values": [0.1, 0.7],
"x_axis": ["2010-03-31T00:00:00", "2010-12-26T00:00:00"],
}
],
"/ensembles/ens_id_3/records/SNAKE_OIL_WPR_DIFF@199/observations": [
{
"name": "SNAKE_OIL_WPR_DIFF",
"errors": [0.05, 0.07, 0.05],
"values": [0.1, 0.7, 0.5],
"x_axis": [
"2010-03-31T00:00:00",
"2010-12-26T00:00:00",
"2011-12-21T00:00:00",
],
}
],
"/ensembles/ens_id_4/records/SNAKE_OIL_WPR_DIFF@199/observations": [
{
"name": "WOPR:OP1",
"errors": [0.05, 0.07, 0.05],
"values": [0.1, 0.7, 0.5],
"x_axis": [
"2010-03-31T00:00:00",
"2010-12-26T00:00:00",
"2011-12-21T00:00:00",
],
}
],
"/ensembles/ens_id_3/records/FOPR/observations": [
{
"name": "FOPR",
"errors": [0.05, 0.07],
"values": [0.1, 0.7],
"x_axis": ["2010-03-31T00:00:00", "2010-12-26T00:00:00"],
}
],
}
parameters = {
"/ensembles/ens_id_1/parameters": [
{
Expand Down Expand Up @@ -161,6 +213,14 @@ def mocked_requests_get(*args, **kwargs):
"userdata": {"data_origin": "GEN_KW"},
},
],
"/ensembles/ens_id_5/parameters": [
{
"name": "I_AM_A_PARAM",
"dimensionality": 1,
"labels": [],
"userdata": {"data_origin": "GEN_KW"},
},
],
}

responses = {
Expand Down Expand Up @@ -198,12 +258,21 @@ def mocked_requests_get(*args, **kwargs):
"has_observations": False,
},
},
"/ensembles/ens_id_5/responses": {
"WOPPER": {
"name": "WOPPER",
"id": "id_999",
"userdata": {"data_origin": "Summary"},
"has_observations": False,
},
},
}

ensembles = {
"/experiments/exp_1/ensembles": [
{"id": "ens_id_1", "userdata": {"name": "ensemble_1"}, "size": 25},
{"id": "ens_id_3", "userdata": {"name": "default_0"}, "size": 99},
{"id": "ens_id_5", "userdata": {"name": "default_manyobs"}, "size": 25},
]
}

Expand All @@ -220,7 +289,13 @@ def mocked_requests_get(*args, **kwargs):
{
"name": "default",
"id": "exp_1",
"ensemble_ids": ["ens_id_1", "ens_id_2", "ens_id_3", "ens_id_4"],
"ensemble_ids": [
"ens_id_1",
"ens_id_2",
"ens_id_3",
"ens_id_4",
"ens_id_5",
],
"priors": {},
"userdata": {},
}
Expand All @@ -230,7 +305,7 @@ def mocked_requests_get(*args, **kwargs):
return MockResponse({"userdata": ensemble[args[0]]}, 200)
elif args[0] in observations:
return MockResponse(
[observations[args[0]]],
observations[args[0]],
200,
)
elif args[0] in ensembles:
Expand Down
14 changes: 13 additions & 1 deletion tests/unit_tests/gui/tools/plot/test_plot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def test_case_structure(api):
hidden_case = [
ensemble.name for ensemble in api.get_all_ensembles() if ensemble.hidden
]
expected = ["ensemble_1", ".ensemble_2", "default_0", "default_1"]
expected = [
"ensemble_1",
".ensemble_2",
"default_0",
"default_1",
"default_manyobs",
]

assert ensembles == expected
assert hidden_case == [".ensemble_2"]
Expand Down Expand Up @@ -246,3 +252,9 @@ def test_plot_api_handles_non_existant_gen_kw(api_and_storage):
)
assert api.data_for_key(str(ensemble.id), "gen_kw").empty
assert api.data_for_key(str(ensemble.id), "gen_kw:does_not_exist").empty


def test_that_multiple_observations_are_parsed_correctly(api):
ensemble = next(x for x in api.get_all_ensembles() if x.id == "ens_id_5")
obs_data = api.observations_for_key([ensemble.id], "WOPR:OP1")
assert obs_data.shape == (3, 6)

0 comments on commit 83b303d

Please sign in to comment.