mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
This commit is contained in:
@@ -6,14 +6,14 @@ sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
from Empty_pb2 import Empty
|
||||
|
||||
import AppInfo_pb2
|
||||
import AppInfo_pb2_grpc
|
||||
import App_pb2
|
||||
import App_pb2_grpc
|
||||
|
||||
class AppInfo:
|
||||
class App:
|
||||
def __init__(self, channel):
|
||||
self.appInfo = AppInfo_pb2_grpc.AppInfoStub(channel)
|
||||
self.app = App_pb2_grpc.AppStub(channel)
|
||||
def versionMessage(self):
|
||||
return self.appInfo.GetVersion(Empty())
|
||||
return self.app.GetVersion(Empty())
|
||||
def majorVersion(self):
|
||||
return self.versionMessage().major_version
|
||||
def minorVersion(self):
|
||||
@@ -22,4 +22,5 @@ class AppInfo:
|
||||
return self.versionMessage().patch_version
|
||||
def versionString(self):
|
||||
return str(self.majorVersion()) + "." + str(self.minorVersion()) + "." + str(self.patchVersion())
|
||||
|
||||
def exit(self):
|
||||
return self.app.Exit(Empty())
|
||||
@@ -20,7 +20,7 @@ class Case:
|
||||
self.type = info.type
|
||||
self.properties = Properties(self)
|
||||
self.request = Case_pb2.CaseRequest(id=self.id)
|
||||
|
||||
|
||||
def gridCount(self):
|
||||
try:
|
||||
return self.stub.GetGridCount(self.request).count
|
||||
|
||||
@@ -8,7 +8,7 @@ sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
import RiaVersionInfo
|
||||
|
||||
from .AppInfo import AppInfo
|
||||
from .App import App
|
||||
from .Commands import Commands
|
||||
from .Project import Project
|
||||
|
||||
@@ -60,10 +60,10 @@ class Instance:
|
||||
self.channel = grpc.insecure_channel(location)
|
||||
|
||||
# Main version check package
|
||||
self.appInfo = AppInfo(self.channel)
|
||||
self.app = App(self.channel)
|
||||
try:
|
||||
majorVersionOk = self.appInfo.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION)
|
||||
minorVersionOk = self.appInfo.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION)
|
||||
majorVersionOk = self.app.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION)
|
||||
minorVersionOk = self.app.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION)
|
||||
if not (majorVersionOk and minorVersionOk):
|
||||
raise Exception('Version of ResInsight does not match version of Python API')
|
||||
except grpc.RpcError as e:
|
||||
|
||||
@@ -44,3 +44,7 @@ class Project:
|
||||
return case
|
||||
except grpc.RpcError as e:
|
||||
return None
|
||||
|
||||
def loadCase(self, path):
|
||||
return Commands(self.channel).loadCase(path)
|
||||
|
||||
|
||||
16
ApplicationCode/GrpcInterface/Python/tests/conftest.py
Normal file
16
ApplicationCode/GrpcInterface/Python/tests/conftest.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
instance = rips.Instance.launch()
|
||||
|
||||
@pytest.fixture
|
||||
def rips_instance():
|
||||
return instance
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
print("Telling ResInsight to Exit")
|
||||
instance.app.exit()
|
||||
1
ApplicationCode/GrpcInterface/Python/tests/dataroot.py
Normal file
1
ApplicationCode/GrpcInterface/Python/tests/dataroot.py
Normal file
@@ -0,0 +1 @@
|
||||
PATH = "../../../TestModels"
|
||||
19
ApplicationCode/GrpcInterface/Python/tests/test_cases.py
Normal file
19
ApplicationCode/GrpcInterface/Python/tests/test_cases.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
import dataroot
|
||||
|
||||
def test_Launch(rips_instance):
|
||||
assert(rips_instance is not None)
|
||||
|
||||
def test_EmptyProject(rips_instance):
|
||||
cases = rips_instance.project.cases()
|
||||
assert(len(cases) is 0)
|
||||
|
||||
def test_OneCase(rips_instance):
|
||||
case = rips_instance.project.loadCase(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
|
||||
cases = rips_instance.project.cases()
|
||||
assert(len(cases) is 1)
|
||||
@@ -1,51 +0,0 @@
|
||||
|
||||
import os, sys
|
||||
|
||||
# Add the 'api' path to system path to be able to import modules from the 'api' folder
|
||||
# python current working directory must be 'tests'
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..\\api'))
|
||||
|
||||
import ResInsight
|
||||
|
||||
resInsight = ResInsight.Instance()
|
||||
|
||||
|
||||
# content of test_sample.py
|
||||
def getActiveCellCount(caseId):
|
||||
activeCellInfoChunks = resInsight.gridInfo.streamActiveCellInfo(caseId)
|
||||
|
||||
receivedActiveCells = []
|
||||
for activeCellChunk in activeCellInfoChunks:
|
||||
for activeCell in activeCellChunk.data:
|
||||
receivedActiveCells.append(activeCell)
|
||||
return len(receivedActiveCells)
|
||||
|
||||
def myOpenProject(filepath):
|
||||
resInsight = ResInsight.Instance()
|
||||
#resInsight.commands.setMainWindowSize(width=800, height=500)
|
||||
resInsight.commands.openProject(filepath)
|
||||
|
||||
def test_openProjectAndCountCells():
|
||||
testRepositoryRoot = "d:\\gitroot-ceesol\\ResInsight-regression-test"
|
||||
|
||||
#casePath = testRepositoryRoot + "\\ModelData\\TEST10K_FLT_LGR_NNC\\TEST10K_FLT_LGR_NNC.EGRID"
|
||||
#openEclipseCase(casePath)
|
||||
|
||||
# projectPath = testRepositoryRoot + "\\ProjectFiles\\ProjectFilesSmallTests\\TestCase_10K_Complete\\RegressionTest.rsp"
|
||||
# projectPath = testRepositoryRoot + "\\ProjectFiles\\ProjectFilesSmallTests\\TestCase_Norne\\RegressionTest.rsp"
|
||||
projectPath = testRepositoryRoot + "\\ProjectFiles\\ProjectFilesSmallTests\\TestCase_10K_Watertight\\RegressionTest.rsp"
|
||||
myOpenProject(projectPath)
|
||||
|
||||
assert getActiveCellCount(0) == 11125
|
||||
|
||||
|
||||
|
||||
def test_openCaseAndCountCells():
|
||||
testRepositoryRoot = "d:\\gitroot-ceesol\\ResInsight-regression-test"
|
||||
|
||||
casePath = testRepositoryRoot + "\\ModelData\\TEST10K_FLT_LGR_NNC\\TEST10K_FLT_LGR_NNC.EGRID"
|
||||
resInsight.commands.loadCase(casePath)
|
||||
|
||||
assert getActiveCellCount(0) == 11125
|
||||
|
||||
resInsight.commands.closeProject()
|
||||
Reference in New Issue
Block a user