From ac43c9ac71002d02da394e2e5fee9d36feb59b03 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 20 May 2026 20:42:03 +0200 Subject: [PATCH] #4468 Python: Add tests for Project save, views, well_path_by_name, grid_case_groups, key_values_async Cover the easily-reachable gaps in Project API test coverage: save() round trip, views()/view() lookup, well_path_by_name() hit and miss, the grid_case_groups()/grid_case_group(id) lookup pair, and the async key_values iterator. --- .../Python/rips/tests/test_key_value_store.py | 15 +++++ .../Python/rips/tests/test_project.py | 55 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/GrpcInterface/Python/rips/tests/test_key_value_store.py b/GrpcInterface/Python/rips/tests/test_key_value_store.py index de38d00d2b..14c4c7c193 100644 --- a/GrpcInterface/Python/rips/tests/test_key_value_store.py +++ b/GrpcInterface/Python/rips/tests/test_key_value_store.py @@ -16,6 +16,21 @@ def test_set_and_get_values(rips_instance, initialize_test): assert input_values == output_values +def test_set_and_get_values_async(rips_instance, initialize_test): + project = rips_instance.project + key = "my-async-key" + input_values = [float(x) for x in range(2000)] + project.set_key_values(key, input_values) + + accumulated = [] + chunk_count = 0 + for chunk in project.key_values_async(key): + accumulated.extend(chunk.values) + chunk_count += 1 + assert chunk_count > 0 + assert input_values == accumulated + + def test_get_non_existing_key(rips_instance, initialize_test): project = rips_instance.project key = "this-key-does-not-exist" diff --git a/GrpcInterface/Python/rips/tests/test_project.py b/GrpcInterface/Python/rips/tests/test_project.py index 918c062af8..19b5e6b1cf 100644 --- a/GrpcInterface/Python/rips/tests/test_project.py +++ b/GrpcInterface/Python/rips/tests/test_project.py @@ -66,6 +66,61 @@ def test_loadGridCaseGroup(rips_instance, initialize_test): ) assert grid_case_group is not None and grid_case_group.group_id == 0 + project = rips_instance.project + groups = project.grid_case_groups() + assert len(groups) == 1 + looked_up = project.grid_case_group(grid_case_group.group_id) + assert looked_up is not None + assert looked_up.group_id == grid_case_group.group_id + assert project.grid_case_group(9999) is None + + +def test_save_project_round_trip(rips_instance, initialize_test): + case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" + project = rips_instance.project + project.load_case(case_path) + assert len(project.cases()) == 1 + + with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: + project_file = os.path.join(tmpdirname, "round_trip.rsp") + project.save(project_file) + assert os.path.exists(project_file) + + project.close() + assert len(rips_instance.project.cases()) == 0 + + reopened = rips_instance.project.open(project_file) + cases = reopened.cases() + assert len(cases) == 1 + assert cases[0].name == "TEST10K_FLT_LGR_NNC" + + +def test_views_and_view_lookup(rips_instance, initialize_test): + case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" + case = rips_instance.project.load_case(case_path) + case.create_view() + + project = rips_instance.project + views = project.views() + assert len(views) >= 1 + + first_view = views[0] + looked_up = project.view(first_view.id) + assert looked_up is not None + assert looked_up.id == first_view.id + assert project.view(999999) is None + + +def test_well_path_by_name(rips_instance, initialize_test): + well_files = [dataroot.PATH + "/TEST10K_FLT_LGR_NNC/wellpath_a.dev"] + rips_instance.project.import_well_paths(well_path_files=well_files) + + project = rips_instance.project + well_path = project.well_path_by_name("Well Path A") + assert well_path is not None + assert well_path.name == "Well Path A" + assert project.well_path_by_name("Nonexistent Well Path") is None + def test_exportSnapshots(rips_instance, initialize_test): if not rips_instance.is_gui():