mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Python: move examples, tests and generated inside rips folder so they are packaged in rips pip-package
This commit is contained in:
38
ApplicationCode/GrpcInterface/Python/rips/tests/conftest.py
Normal file
38
ApplicationCode/GrpcInterface/Python/rips/tests/conftest.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
_rips_instance = None
|
||||
|
||||
@pytest.fixture
|
||||
def rips_instance():
|
||||
return _rips_instance
|
||||
|
||||
@pytest.fixture
|
||||
def initializeTest():
|
||||
_rips_instance.project.close()
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--console", action="store_true", default=False, help="Run as console application")
|
||||
parser.addoption("--existing", action="store_true", default=False, help="Look for existing ResInsight")
|
||||
|
||||
def pytest_configure(config):
|
||||
global _rips_instance
|
||||
console = False
|
||||
if config.getoption('--existing'):
|
||||
print("Looking for existing ResInsight")
|
||||
_rips_instance = rips.Instance.find()
|
||||
else:
|
||||
if config.getoption('--console'):
|
||||
console = True
|
||||
_rips_instance = rips.Instance.launch(console=console)
|
||||
if not _rips_instance:
|
||||
print("Need a valid ResInsight executable to launch tests")
|
||||
exit(0)
|
||||
|
||||
def pytest_unconfigure():
|
||||
_rips_instance.app.exit()
|
||||
@@ -0,0 +1 @@
|
||||
PATH = "../../../../TestModels"
|
||||
@@ -0,0 +1,64 @@
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
def test_Launch(rips_instance, initializeTest):
|
||||
assert(rips_instance is not None)
|
||||
|
||||
def test_EmptyProject(rips_instance, initializeTest):
|
||||
cases = rips_instance.project.cases()
|
||||
assert(len(cases) is 0)
|
||||
|
||||
def test_OneCase(rips_instance, initializeTest):
|
||||
case = rips_instance.project.loadCase(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
|
||||
assert(case.name == "TEST10K_FLT_LGR_NNC")
|
||||
assert(case.id == 0)
|
||||
cases = rips_instance.project.cases()
|
||||
assert(len(cases) is 1)
|
||||
|
||||
def test_MultipleCases(rips_instance, initializeTest):
|
||||
casePaths = []
|
||||
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
|
||||
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
|
||||
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
|
||||
|
||||
caseNames = []
|
||||
for casePath in casePaths:
|
||||
caseName = os.path.splitext(os.path.basename(casePath))[0]
|
||||
caseNames.append(caseName)
|
||||
rips_instance.project.loadCase(path=casePath)
|
||||
|
||||
cases = rips_instance.project.cases()
|
||||
assert(len(cases) == len(caseNames))
|
||||
for i, caseName in enumerate(caseNames):
|
||||
assert(caseName == cases[i].name)
|
||||
|
||||
def test_10k(rips_instance, initializeTest):
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.loadCase(path=casePath)
|
||||
assert(case.gridCount() == 2)
|
||||
cellCountInfo = case.cellCount()
|
||||
assert(cellCountInfo.active_cell_count == 11125)
|
||||
assert(cellCountInfo.reservoir_cell_count == 316224)
|
||||
timeSteps = case.timeSteps()
|
||||
assert(len(timeSteps) == 9)
|
||||
daysSinceStart = case.daysSinceStart()
|
||||
assert(len(daysSinceStart) == 9)
|
||||
|
||||
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
|
||||
def test_brugge_0010(rips_instance, initializeTest):
|
||||
casePath = dataroot.PATH + "/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID"
|
||||
case = rips_instance.project.loadCase(path=casePath)
|
||||
assert(case.gridCount() == 1)
|
||||
cellCountInfo = case.cellCount()
|
||||
assert(cellCountInfo.active_cell_count == 43374)
|
||||
assert(cellCountInfo.reservoir_cell_count == 60048)
|
||||
timeSteps = case.timeSteps()
|
||||
assert(len(timeSteps) == 11)
|
||||
daysSinceStart = case.daysSinceStart()
|
||||
assert(len(daysSinceStart) == 11)
|
||||
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
def test_exportSnapshots(rips_instance, initializeTest):
|
||||
if not rips_instance.app.isGui():
|
||||
pytest.skip("Cannot run test without a GUI")
|
||||
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
rips_instance.project.loadCase(casePath)
|
||||
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||
print("Temporary folder: ", tmpdirname)
|
||||
rips_instance.commands.setExportFolder(type='SNAPSHOTS', path=tmpdirname)
|
||||
rips_instance.commands.exportSnapshots()
|
||||
print(os.listdir(tmpdirname))
|
||||
assert(len(os.listdir(tmpdirname)) > 0)
|
||||
for fileName in os.listdir(tmpdirname):
|
||||
assert(os.path.splitext(fileName)[1] == '.png')
|
||||
|
||||
def test_exportPropertyInView(rips_instance, initializeTest):
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
rips_instance.project.loadCase(casePath)
|
||||
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||
print("Temporary folder: ", tmpdirname)
|
||||
rips_instance.commands.setExportFolder(type='PROPERTIES', path=tmpdirname)
|
||||
case = rips_instance.project.case(id=0)
|
||||
rips_instance.commands.exportPropertyInViews(0, "3D View", 0)
|
||||
expectedFileName = case.name + "-" + str("3D_View") + "-" + "T0" + "-SOIL"
|
||||
fullPath = tmpdirname + "/" + expectedFileName
|
||||
assert(os.path.exists(fullPath))
|
||||
@@ -0,0 +1,17 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
def test_10k(rips_instance, initializeTest):
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.loadCase(path=casePath)
|
||||
assert(case.gridCount() == 2)
|
||||
grid = case.grid(index=0)
|
||||
dimensions = grid.dimensions()
|
||||
assert(dimensions.i == 90)
|
||||
assert(dimensions.j == 96)
|
||||
assert(dimensions.k == 36)
|
||||
@@ -0,0 +1,17 @@
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
def test_loadProject(rips_instance, initializeTest):
|
||||
project = rips_instance.project.open(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp")
|
||||
case = project.case(id=0)
|
||||
assert(case is not None)
|
||||
assert(case.name == "TEST10K_FLT_LGR_NNC")
|
||||
assert(case.id == 0)
|
||||
cases = rips_instance.project.cases()
|
||||
assert(len(cases) is 1)
|
||||
@@ -0,0 +1,55 @@
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
def test_10k(rips_instance, initializeTest):
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.loadCase(path=casePath)
|
||||
|
||||
resultChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', 1)
|
||||
mysum = 0.0
|
||||
count = 0
|
||||
for chunk in resultChunks:
|
||||
mysum += sum(chunk.values)
|
||||
count += len(chunk.values)
|
||||
average = mysum / count
|
||||
assert(mysum == pytest.approx(621.768, abs=0.001))
|
||||
assert(average != pytest.approx(0.0158893, abs=0.0000001))
|
||||
assert(average == pytest.approx(0.0558893, abs=0.0000001))
|
||||
|
||||
|
||||
def createResult(poroChunks, permxChunks):
|
||||
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
|
||||
resultChunk = []
|
||||
for (poro, permx) in zip(poroChunk.values, permxChunk.values):
|
||||
resultChunk.append(poro * permx)
|
||||
yield resultChunk
|
||||
|
||||
def checkResults(poroChunks, permxChunks, poroPermXChunks):
|
||||
for (poroChunk, permxChunk, poroPermXChunk) in zip(poroChunks, permxChunks, poroPermXChunks):
|
||||
for (poro, permx, poropermx) in zip(poroChunk.values, permxChunk.values, poroPermXChunk.values):
|
||||
recalc = poro * permx
|
||||
assert(recalc == pytest.approx(poropermx, rel=1.0e-10))
|
||||
|
||||
def test_10k_PoroPermX(rips_instance, initializeTest):
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.loadCase(path=casePath)
|
||||
|
||||
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
|
||||
|
||||
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks), 'GENERATED', 'POROPERMXAS', 0)
|
||||
|
||||
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
|
||||
poroPermXChunks = case.properties.activeCellProperty('GENERATED', 'POROPERMXAS', 0)
|
||||
|
||||
checkResults(poroChunks, permxChunks, poroPermXChunks)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user