mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-27 15:41:00 -05:00
Fill the async-variant gaps in Properties / NNCProperties coverage that already have sync tests: selected_cells_async, selected_cell_property_async, nnc_connections_static_values_async, nnc_connections_generated_values_async. Each test accumulates the streamed chunks and asserts equality with the corresponding synchronous call. Fixes #4465.
123 lines
4.1 KiB
Python
123 lines
4.1 KiB
Python
import sys
|
|
import os
|
|
import pytest
|
|
|
|
import rips.generated.NNCProperties_pb2 as NNCProperties_pb2
|
|
|
|
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
|
import rips
|
|
|
|
import dataroot
|
|
|
|
|
|
def test_10kSync(rips_instance, initialize_test):
|
|
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
|
case = rips_instance.project.load_case(path=casePath)
|
|
|
|
properties = case.available_nnc_properties()
|
|
assert len(properties) == 1
|
|
|
|
assert "TRAN" == properties[0].name
|
|
assert (
|
|
NNCProperties_pb2.NNCPropertyType.Value("NNC_STATIC")
|
|
== properties[0].property_type
|
|
)
|
|
|
|
nnc_connections = case.nnc_connections()
|
|
assert len(nnc_connections) == 3416
|
|
|
|
connection = nnc_connections[0]
|
|
assert connection.cell1.i == 33
|
|
assert connection.cell1.j == 40
|
|
assert connection.cell1.k == 14
|
|
assert connection.cell_grid_index1 == 0
|
|
|
|
tran_vals = case.nnc_connections_static_values("TRAN")
|
|
assert len(tran_vals) == len(nnc_connections)
|
|
|
|
for t in tran_vals:
|
|
assert isinstance(t, float)
|
|
|
|
# Generate some data
|
|
new_data = []
|
|
for c, _ in enumerate(nnc_connections):
|
|
new_data.append(float(c))
|
|
|
|
property_name = "NEW_PROP"
|
|
case.set_nnc_connections_values(new_data, property_name, 0)
|
|
new_prop_vals = case.nnc_connections_generated_values(property_name, 0)
|
|
assert len(new_prop_vals) == len(new_data)
|
|
for i in range(0, len(new_data)):
|
|
assert new_data[i] == new_prop_vals[i]
|
|
|
|
# Set some other data for second time step
|
|
for i in range(0, len(new_data)):
|
|
new_data[i] = new_data[i] * 2.0
|
|
|
|
case.set_nnc_connections_values(new_data, property_name, 1)
|
|
new_prop_vals = case.nnc_connections_generated_values(property_name, 1)
|
|
assert len(new_prop_vals) == len(nnc_connections)
|
|
for i in range(0, len(new_data)):
|
|
assert new_data[i] == new_prop_vals[i]
|
|
|
|
|
|
def test_10k_nnc_connections_async(rips_instance, initialize_test):
|
|
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
|
case = rips_instance.project.load_case(path=casePath)
|
|
|
|
accumulated = []
|
|
chunk_count = 0
|
|
for chunk in case.nnc_connections_async():
|
|
accumulated.extend(chunk.connections)
|
|
chunk_count += 1
|
|
assert chunk_count > 0
|
|
|
|
sync_connections = case.nnc_connections()
|
|
assert len(accumulated) == len(sync_connections)
|
|
|
|
first = accumulated[0]
|
|
assert first.cell1.i == 33
|
|
assert first.cell1.j == 40
|
|
assert first.cell1.k == 14
|
|
assert first.cell_grid_index1 == 0
|
|
|
|
|
|
def test_10k_nnc_connections_static_values_async(rips_instance, initialize_test):
|
|
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
|
case = rips_instance.project.load_case(path=casePath)
|
|
|
|
accumulated = []
|
|
for chunk in case.nnc_connections_static_values_async("TRAN"):
|
|
accumulated.extend(chunk.values)
|
|
assert accumulated == case.nnc_connections_static_values("TRAN")
|
|
|
|
|
|
def test_10k_nnc_connections_generated_values_async(rips_instance, initialize_test):
|
|
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
|
case = rips_instance.project.load_case(path=casePath)
|
|
|
|
nnc_connections = case.nnc_connections()
|
|
new_data = [float(c) for c, _ in enumerate(nnc_connections)]
|
|
property_name = "ASYNC_PROP"
|
|
case.set_nnc_connections_values(new_data, property_name, 0)
|
|
|
|
accumulated = []
|
|
for chunk in case.nnc_connections_generated_values_async(property_name, 0):
|
|
accumulated.extend(chunk.values)
|
|
assert accumulated == new_data
|
|
|
|
|
|
def test_non_existing_dynamic_values(rips_instance, initialize_test):
|
|
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
|
case = rips_instance.project.load_case(path=casePath)
|
|
|
|
with pytest.raises(rips.RipsError):
|
|
case.nnc_connections_dynamic_values("x", 0)
|
|
|
|
|
|
def test_invalid_time_steps(rips_instance, initialize_test):
|
|
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
|
case = rips_instance.project.load_case(path=casePath)
|
|
with pytest.raises(rips.RipsError):
|
|
case.nnc_connections_generated_values("Formation Allan", 9999)
|