#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,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

View File

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