#4460 Further gRPC/Python tests

This commit is contained in:
Gaute Lindkvist 2019-06-04 20:35:30 +02:00
parent 8bbbaec9df
commit 196e7df0fa
7 changed files with 91 additions and 19 deletions

View File

@ -2,8 +2,10 @@ import grpc
import os
import sys
from Empty_pb2 import Empty
import Commands_pb2 as Cmd
import Commands_pb2_grpc as CmdRpc
from .Case import Case
class Commands:
def __init__(self, channel):
@ -35,7 +37,7 @@ class Commands:
def loadCase(self, path):
commandReply = self.execute(loadCase=Cmd.FilePathRequest(path=path))
assert commandReply.HasField("loadCaseResult")
return commandReply.loadCaseResult.id
return Case(self.channel, commandReply.loadCaseResult.id)
def replaceCase(self, path, caseId=0):
return self.execute(replaceCase=Cmd.ReplaceCaseRequest(newGridFile=path,

View File

@ -20,14 +20,15 @@ class Instance:
return s.connect_ex(('localhost', port)) == 0
@staticmethod
def launch():
def launch(resInsightExecutable = ''):
port = 50051
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
if portEnv:
port = int(portEnv)
if not resInsightExecutable:
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
if resInsightExecutable is None:
if not resInsightExecutable:
print('Error: Could not launch any ResInsight instances because RESINSIGHT_EXECUTABLE is not set')
return None

View File

@ -16,6 +16,13 @@ class Project:
self.channel = channel
self.project = Project_pb2_grpc.ProjectStub(channel)
def open(self, path):
Commands(self.channel).openProject(path)
return self
def close(self):
Commands(self.channel).closeProject()
def selectedCases(self):
caseInfos = self.project.GetSelectedCases(Empty())
cases = []

View File

@ -7,10 +7,17 @@ import rips
instance = rips.Instance.launch()
if (not instance):
exit(1)
@pytest.fixture
def rips_instance():
return instance
@pytest.fixture
def initializeTest():
instance.project.close()
def pytest_unconfigure(config):
print("Telling ResInsight to Exit")
instance.app.exit()

View File

@ -6,26 +6,25 @@ import rips
import dataroot
def test_Launch(rips_instance):
def test_Launch(rips_instance, initializeTest):
assert(rips_instance is not None)
def test_EmptyProject(rips_instance):
def test_EmptyProject(rips_instance, initializeTest):
cases = rips_instance.project.cases()
assert(len(cases) is 0)
def test_OneCase(rips_instance):
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):
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")
casePaths.append(dataroot.PATH + "/case_with_10_timesteps/Real0/BRUGGE_0000.EGRID")
casePaths.append(dataroot.PATH + "/case_with_10_timesteps/Real10/BRUGGE_0010.EGRID")
casePaths.append(dataroot.PATH + "/case_with_10_timesteps/Real20/BRUGGE_0020.EGRID")
casePaths.append(dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID")
casePaths.append(dataroot.PATH + "/Case_with_10_timesteps/Real30/BRUGGE_0030.EGRID")
caseNames = []
for casePath in casePaths:
@ -33,11 +32,27 @@ def test_MultipleCases(rips_instance):
caseNames.append(caseName)
rips_instance.project.loadCase(path=casePath)
print(caseNames)
cases = rips_instance.project.cases()
for case in cases:
print (case.index, case.name)
assert(len(cases) == len(caseNames))
for i, caseName in enumerate(caseNames):
print(i, caseName)
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.dates) == 9)
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.dates) == 11)

View File

@ -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)

View File

@ -0,0 +1,23 @@
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))