Fix Pytest failures

This commit is contained in:
Gaute Lindkvist 2019-10-09 10:30:07 +02:00
parent 411e5cf49f
commit 9f0cf91789
6 changed files with 37 additions and 18 deletions

View File

@ -42,13 +42,12 @@ class Case(PdmObject):
self.__channel = channel
self.__case_stub = Case_pb2_grpc.CaseStub(channel)
self.__request = Case_pb2.CaseRequest(id=case_id)
self.__project = project
info = self.__case_stub.GetCaseInfo(self.__request)
self.__properties_stub = Properties_pb2_grpc.PropertiesStub(
self.__channel)
PdmObject.__init__(self, self.__case_stub.GetPdmObject(self.__request),
self.__channel)
self.__channel, project)
# Public properties
self.case_id = case_id
@ -128,7 +127,7 @@ class Case(PdmObject):
"""
self._execute_command(replaceCase=Cmd.ReplaceCaseRequest(
newGridFile=new_grid_file, caseId=self.case_id))
self.__init__(self.__channel, self.case_id)
self.__init__(self.__channel, self.case_id, self._project)
def cell_count(self, porosity_model="MATRIX_MODEL"):
"""Get a cell count object containing number of active cells and
@ -228,7 +227,7 @@ class Case(PdmObject):
pdm_objects = self.children("ReservoirViews")
view_list = []
for pdm_object in pdm_objects:
view_list.append(View(pdm_object))
view_list.append(View(pdm_object, self._project))
return view_list
def view(self, view_id):
@ -750,7 +749,7 @@ class Case(PdmObject):
plot_result = self._execute_command(createWellBoreStabilityPlot=Cmd.CreateWbsPlotRequest(caseId=self.case_id,
wellPath=well_path,
timeStep=time_step))
return self.__project.plot(view_id=plot_result.createWbsPlotResult.viewId)
return self._project.plot(view_id=plot_result.createWbsPlotResult.viewId)
def import_formation_names(self, formation_files=None):
""" Import formation names into project and apply it to the current case

View File

@ -19,7 +19,7 @@ class GridCaseGroup(PdmObject):
"""
def __init__(self, pdm_object):
self.group_id = pdm_object.get_value("GroupId")
PdmObject.__init__(self, pdm_object._pb2_object, pdm_object._channel)
PdmObject.__init__(self, pdm_object._pb2_object, pdm_object._channel, pdm_object._project)
def create_statistics_case(self):
"""Create a Statistics case in the Grid Case Group

View File

@ -39,6 +39,21 @@ class Instance:
my_socket.settimeout(0.2)
return my_socket.connect_ex(('localhost', port)) == 0
@staticmethod
def __is_valid_port(port):
location = "localhost:" + str(port)
channel = grpc.insecure_channel(location,
options=[
('grpc.enable_http_proxy',
False)
])
app = App_pb2_grpc.AppStub(channel)
try:
app.GetVersion(Empty(), timeout=1)
except grpc.RpcError:
return False
return True
@staticmethod
def launch(resinsight_executable='',
console=False,
@ -75,8 +90,10 @@ class Instance:
' RESINSIGHT_EXECUTABLE is not set')
return None
while Instance.__is_port_in_use(port):
print("Trying port " + str(port))
while Instance.__is_port_in_use(port):
port += 1
print("Trying port " + str(port))
print('Port ' + str(port))
print('Trying to launch', resinsight_executable)
@ -116,11 +133,13 @@ class Instance:
"""
port_env = os.environ.get('RESINSIGHT_GRPC_PORT')
if port_env:
print("Got port " + port_env + " from environment")
start_port = int(port_env)
end_port = start_port + 20
for try_port in range(start_port, end_port):
if Instance.__is_port_in_use(try_port):
print("Trying port " + str(try_port))
if Instance.__is_port_in_use(try_port) and Instance.__is_valid_port(try_port):
return Instance(port=try_port)
print(
@ -159,7 +178,7 @@ class Instance:
self.commands = CmdRpc.CommandsStub(self.channel)
# Main version check package
self.app = self.app = App_pb2_grpc.AppStub(self.channel)
self.app = App_pb2_grpc.AppStub(self.channel)
connection_ok = False
version_ok = False

View File

@ -23,11 +23,12 @@ class PdmObject:
return response
def __init__(self, pb2_object, channel):
def __init__(self, pb2_object, channel, project):
self._pb2_object = pb2_object
self._channel = channel
self._pdm_object_stub = PdmObject_pb2_grpc.PdmObjectServiceStub(self._channel)
self._commands = CmdRpc.CommandsStub(channel)
self._project = project
self.__warnings = []
def warnings(self):
@ -149,7 +150,7 @@ class PdmObject:
request).objects
child_list = []
for pdm_object in object_list:
child_list.append(PdmObject(pdm_object, self._channel))
child_list.append(PdmObject(pdm_object, self._channel, self._project))
return child_list
def children(self, child_field):
@ -164,7 +165,7 @@ class PdmObject:
object_list = self._pdm_object_stub.GetChildPdmObjects(request).objects
child_list = []
for pdm_object in object_list:
child_list.append(PdmObject(pdm_object, self._channel))
child_list.append(PdmObject(pdm_object, self._channel, self._project))
return child_list
def ancestor(self, class_keyword):
@ -175,7 +176,7 @@ class PdmObject:
request = PdmObject_pb2.PdmParentObjectRequest(
object=self._pb2_object, parent_keyword=class_keyword)
return PdmObject(self._pdm_object_stub.GetAncestorPdmObject(request),
self._channel)
self._channel, self._project)
def update(self):
"""Sync all fields from the Python Object to ResInsight"""

View File

@ -24,7 +24,7 @@ class Project(PdmObject):
def __init__(self, channel):
self._project_stub = Project_pb2_grpc.ProjectStub(channel)
PdmObject.__init__(self, self._project_stub.GetPdmObject(Empty()),
channel)
channel, self)
def open(self, path):
"""Open a new project from the given path
@ -127,7 +127,7 @@ class Project(PdmObject):
pdm_objects = self.descendants("ReservoirView")
view_list = []
for pdm_object in pdm_objects:
view_list.append(View(pdm_object))
view_list.append(View(pdm_object, self._project))
return view_list
def view(self, view_id):

View File

@ -14,8 +14,8 @@ class View(PdmObject):
view_id(int): View Id corresponding to the View Id in ResInsight project.
"""
def __init__(self, pdm_object):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel())
def __init__(self, pdm_object, project):
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), project)
self.view_id = pdm_object.get_value("ViewId")
def show_grid_box(self):
@ -103,7 +103,7 @@ class View(PdmObject):
pdm_case = self.ancestor("ResInsightGeoMechCase")
if pdm_case is None:
return None
return rips.case.Case(self._channel, pdm_case.get_value("CaseId"))
return rips.case.Case(self._channel, pdm_case.get_value("CaseId"), self._project)
def clone(self):
"""Clone the current view"""