mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4460 Further gRPC/Python tests
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -20,16 +20,17 @@ 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)
|
||||
|
||||
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
||||
if resInsightExecutable is None:
|
||||
print('Error: Could not launch any ResInsight instances because RESINSIGHT_EXECUTABLE is not set')
|
||||
return None
|
||||
if not resInsightExecutable:
|
||||
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
||||
if not resInsightExecutable:
|
||||
print('Error: Could not launch any ResInsight instances because RESINSIGHT_EXECUTABLE is not set')
|
||||
return None
|
||||
|
||||
while Instance.is_port_in_use(port):
|
||||
port += 1
|
||||
|
||||
@@ -15,6 +15,13 @@ class Project:
|
||||
def __init__(self, channel):
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user