#4736 System python command refactor (#4743)

* Move case loading commands from Commands to project and case
* Major refactor
* Fix problems with Python examples
* Add ability to export snapshot from just one view + fixup
* Case comments and black
* Make all modules pass pylint test
This commit is contained in:
Gaute Lindkvist
2019-09-23 11:50:33 +02:00
committed by GitHub
parent 00eb02ccec
commit a2bad82391
54 changed files with 1753 additions and 1432 deletions

View File

@@ -1,6 +1,8 @@
import sys
import os
import pytest
import grpc
import tempfile
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
@@ -17,7 +19,7 @@ def test_EmptyProject(rips_instance, initialize_test):
def test_OneCase(rips_instance, initialize_test):
case = rips_instance.project.load_case(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
assert(case.name == "TEST10K_FLT_LGR_NNC")
assert(case.id == 0)
assert(case.case_id == 0)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
@@ -41,7 +43,7 @@ def test_MultipleCases(rips_instance, initialize_test):
def test_10k(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(case.grid_count() == 2)
assert(len(case.grids()) == 2)
cell_count_info = case.cell_count()
assert(cell_count_info.active_cell_count == 11125)
assert(cell_count_info.reservoir_cell_count == 316224)
@@ -53,17 +55,17 @@ def test_10k(rips_instance, initialize_test):
def test_PdmObject(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(case.id == 0)
assert(case.case_id == 0)
assert(case.address() is not 0)
assert(case.class_keyword() == "EclipseCase")
case_id = case.get_value('CaseId')
assert(case_id == case.id)
assert(case_id == case.case_id)
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_brugge_0010(rips_instance, initialize_test):
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID"
case = rips_instance.project.load_case(path=case_path)
assert(case.grid_count() == 1)
assert(len(case.grids()) == 1)
cellCountInfo = case.cell_count()
assert(cellCountInfo.active_cell_count == 43374)
assert(cellCountInfo.reservoir_cell_count == 60048)
@@ -76,16 +78,36 @@ def test_brugge_0010(rips_instance, initialize_test):
def test_replaceCase(rips_instance, initialize_test):
project = rips_instance.project.open(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp")
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
case = project.case(id=0)
case = project.case(case_id=0)
assert(case is not None)
assert(case.name == "TEST10K_FLT_LGR_NNC")
assert(case.id == 0)
assert(case.case_id == 0)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
rips_instance.commands.replace_case(new_grid_file=case_path, case_id=case.id)
case.replace(new_grid_file=case_path)
# Check that the case object has been changed
assert(case.name == "Real0--BRUGGE_0000.EGRID")
assert(case.case_id == 0)
cases = rips_instance.project.cases()
assert(len(cases) is 1)
case = project.case(id=0)
# Check that retrieving the case object again will yield the changed object
case = project.case(case_id=0)
assert(case.name == "Real0--BRUGGE_0000.EGRID")
assert(case.id == 0)
assert(case.case_id == 0)
def test_loadNonExistingCase(rips_instance, initialize_test):
case_path = "Nonsense/Nonsense/Nonsense"
with pytest.raises(grpc.RpcError):
assert rips_instance.project.load_case(case_path)
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_exportFlowCharacteristics(rips_instance, initialize_test):
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
case = rips_instance.project.load_case(case_path)
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
print("Temporary folder: ", tmpdirname)
file_name = tmpdirname + "/exportFlowChar.txt"
case.export_flow_characteristics(time_steps=8, producers=[], injectors = "I01", file_name = file_name)