mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Fix Pytest failures
This commit is contained in:
parent
411e5cf49f
commit
9f0cf91789
@ -42,13 +42,12 @@ class Case(PdmObject):
|
|||||||
self.__channel = channel
|
self.__channel = channel
|
||||||
self.__case_stub = Case_pb2_grpc.CaseStub(channel)
|
self.__case_stub = Case_pb2_grpc.CaseStub(channel)
|
||||||
self.__request = Case_pb2.CaseRequest(id=case_id)
|
self.__request = Case_pb2.CaseRequest(id=case_id)
|
||||||
self.__project = project
|
|
||||||
|
|
||||||
info = self.__case_stub.GetCaseInfo(self.__request)
|
info = self.__case_stub.GetCaseInfo(self.__request)
|
||||||
self.__properties_stub = Properties_pb2_grpc.PropertiesStub(
|
self.__properties_stub = Properties_pb2_grpc.PropertiesStub(
|
||||||
self.__channel)
|
self.__channel)
|
||||||
PdmObject.__init__(self, self.__case_stub.GetPdmObject(self.__request),
|
PdmObject.__init__(self, self.__case_stub.GetPdmObject(self.__request),
|
||||||
self.__channel)
|
self.__channel, project)
|
||||||
|
|
||||||
# Public properties
|
# Public properties
|
||||||
self.case_id = case_id
|
self.case_id = case_id
|
||||||
@ -128,7 +127,7 @@ class Case(PdmObject):
|
|||||||
"""
|
"""
|
||||||
self._execute_command(replaceCase=Cmd.ReplaceCaseRequest(
|
self._execute_command(replaceCase=Cmd.ReplaceCaseRequest(
|
||||||
newGridFile=new_grid_file, caseId=self.case_id))
|
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"):
|
def cell_count(self, porosity_model="MATRIX_MODEL"):
|
||||||
"""Get a cell count object containing number of active cells and
|
"""Get a cell count object containing number of active cells and
|
||||||
@ -228,7 +227,7 @@ class Case(PdmObject):
|
|||||||
pdm_objects = self.children("ReservoirViews")
|
pdm_objects = self.children("ReservoirViews")
|
||||||
view_list = []
|
view_list = []
|
||||||
for pdm_object in pdm_objects:
|
for pdm_object in pdm_objects:
|
||||||
view_list.append(View(pdm_object))
|
view_list.append(View(pdm_object, self._project))
|
||||||
return view_list
|
return view_list
|
||||||
|
|
||||||
def view(self, view_id):
|
def view(self, view_id):
|
||||||
@ -750,7 +749,7 @@ class Case(PdmObject):
|
|||||||
plot_result = self._execute_command(createWellBoreStabilityPlot=Cmd.CreateWbsPlotRequest(caseId=self.case_id,
|
plot_result = self._execute_command(createWellBoreStabilityPlot=Cmd.CreateWbsPlotRequest(caseId=self.case_id,
|
||||||
wellPath=well_path,
|
wellPath=well_path,
|
||||||
timeStep=time_step))
|
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):
|
def import_formation_names(self, formation_files=None):
|
||||||
""" Import formation names into project and apply it to the current case
|
""" Import formation names into project and apply it to the current case
|
||||||
|
@ -19,7 +19,7 @@ class GridCaseGroup(PdmObject):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, pdm_object):
|
def __init__(self, pdm_object):
|
||||||
self.group_id = pdm_object.get_value("GroupId")
|
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):
|
def create_statistics_case(self):
|
||||||
"""Create a Statistics case in the Grid Case Group
|
"""Create a Statistics case in the Grid Case Group
|
||||||
|
@ -39,6 +39,21 @@ class Instance:
|
|||||||
my_socket.settimeout(0.2)
|
my_socket.settimeout(0.2)
|
||||||
return my_socket.connect_ex(('localhost', port)) == 0
|
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
|
@staticmethod
|
||||||
def launch(resinsight_executable='',
|
def launch(resinsight_executable='',
|
||||||
console=False,
|
console=False,
|
||||||
@ -75,8 +90,10 @@ class Instance:
|
|||||||
' RESINSIGHT_EXECUTABLE is not set')
|
' RESINSIGHT_EXECUTABLE is not set')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
while Instance.__is_port_in_use(port):
|
print("Trying port " + str(port))
|
||||||
|
while Instance.__is_port_in_use(port):
|
||||||
port += 1
|
port += 1
|
||||||
|
print("Trying port " + str(port))
|
||||||
|
|
||||||
print('Port ' + str(port))
|
print('Port ' + str(port))
|
||||||
print('Trying to launch', resinsight_executable)
|
print('Trying to launch', resinsight_executable)
|
||||||
@ -116,11 +133,13 @@ class Instance:
|
|||||||
"""
|
"""
|
||||||
port_env = os.environ.get('RESINSIGHT_GRPC_PORT')
|
port_env = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||||
if port_env:
|
if port_env:
|
||||||
|
print("Got port " + port_env + " from environment")
|
||||||
start_port = int(port_env)
|
start_port = int(port_env)
|
||||||
end_port = start_port + 20
|
end_port = start_port + 20
|
||||||
|
|
||||||
for try_port in range(start_port, end_port):
|
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)
|
return Instance(port=try_port)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
@ -159,7 +178,7 @@ class Instance:
|
|||||||
self.commands = CmdRpc.CommandsStub(self.channel)
|
self.commands = CmdRpc.CommandsStub(self.channel)
|
||||||
|
|
||||||
# Main version check package
|
# 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
|
connection_ok = False
|
||||||
version_ok = False
|
version_ok = False
|
||||||
|
@ -23,11 +23,12 @@ class PdmObject:
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def __init__(self, pb2_object, channel):
|
def __init__(self, pb2_object, channel, project):
|
||||||
self._pb2_object = pb2_object
|
self._pb2_object = pb2_object
|
||||||
self._channel = channel
|
self._channel = channel
|
||||||
self._pdm_object_stub = PdmObject_pb2_grpc.PdmObjectServiceStub(self._channel)
|
self._pdm_object_stub = PdmObject_pb2_grpc.PdmObjectServiceStub(self._channel)
|
||||||
self._commands = CmdRpc.CommandsStub(channel)
|
self._commands = CmdRpc.CommandsStub(channel)
|
||||||
|
self._project = project
|
||||||
self.__warnings = []
|
self.__warnings = []
|
||||||
|
|
||||||
def warnings(self):
|
def warnings(self):
|
||||||
@ -149,7 +150,7 @@ class PdmObject:
|
|||||||
request).objects
|
request).objects
|
||||||
child_list = []
|
child_list = []
|
||||||
for pdm_object in object_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
|
return child_list
|
||||||
|
|
||||||
def children(self, child_field):
|
def children(self, child_field):
|
||||||
@ -164,7 +165,7 @@ class PdmObject:
|
|||||||
object_list = self._pdm_object_stub.GetChildPdmObjects(request).objects
|
object_list = self._pdm_object_stub.GetChildPdmObjects(request).objects
|
||||||
child_list = []
|
child_list = []
|
||||||
for pdm_object in object_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
|
return child_list
|
||||||
|
|
||||||
def ancestor(self, class_keyword):
|
def ancestor(self, class_keyword):
|
||||||
@ -175,7 +176,7 @@ class PdmObject:
|
|||||||
request = PdmObject_pb2.PdmParentObjectRequest(
|
request = PdmObject_pb2.PdmParentObjectRequest(
|
||||||
object=self._pb2_object, parent_keyword=class_keyword)
|
object=self._pb2_object, parent_keyword=class_keyword)
|
||||||
return PdmObject(self._pdm_object_stub.GetAncestorPdmObject(request),
|
return PdmObject(self._pdm_object_stub.GetAncestorPdmObject(request),
|
||||||
self._channel)
|
self._channel, self._project)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Sync all fields from the Python Object to ResInsight"""
|
"""Sync all fields from the Python Object to ResInsight"""
|
||||||
|
@ -24,7 +24,7 @@ class Project(PdmObject):
|
|||||||
def __init__(self, channel):
|
def __init__(self, channel):
|
||||||
self._project_stub = Project_pb2_grpc.ProjectStub(channel)
|
self._project_stub = Project_pb2_grpc.ProjectStub(channel)
|
||||||
PdmObject.__init__(self, self._project_stub.GetPdmObject(Empty()),
|
PdmObject.__init__(self, self._project_stub.GetPdmObject(Empty()),
|
||||||
channel)
|
channel, self)
|
||||||
|
|
||||||
def open(self, path):
|
def open(self, path):
|
||||||
"""Open a new project from the given path
|
"""Open a new project from the given path
|
||||||
@ -127,7 +127,7 @@ class Project(PdmObject):
|
|||||||
pdm_objects = self.descendants("ReservoirView")
|
pdm_objects = self.descendants("ReservoirView")
|
||||||
view_list = []
|
view_list = []
|
||||||
for pdm_object in pdm_objects:
|
for pdm_object in pdm_objects:
|
||||||
view_list.append(View(pdm_object))
|
view_list.append(View(pdm_object, self._project))
|
||||||
return view_list
|
return view_list
|
||||||
|
|
||||||
def view(self, view_id):
|
def view(self, view_id):
|
||||||
|
@ -14,8 +14,8 @@ class View(PdmObject):
|
|||||||
view_id(int): View Id corresponding to the View Id in ResInsight project.
|
view_id(int): View Id corresponding to the View Id in ResInsight project.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, pdm_object):
|
def __init__(self, pdm_object, project):
|
||||||
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel())
|
PdmObject.__init__(self, pdm_object.pb2_object(), pdm_object.channel(), project)
|
||||||
self.view_id = pdm_object.get_value("ViewId")
|
self.view_id = pdm_object.get_value("ViewId")
|
||||||
|
|
||||||
def show_grid_box(self):
|
def show_grid_box(self):
|
||||||
@ -103,7 +103,7 @@ class View(PdmObject):
|
|||||||
pdm_case = self.ancestor("ResInsightGeoMechCase")
|
pdm_case = self.ancestor("ResInsightGeoMechCase")
|
||||||
if pdm_case is None:
|
if pdm_case is None:
|
||||||
return 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):
|
def clone(self):
|
||||||
"""Clone the current view"""
|
"""Clone the current view"""
|
||||||
|
Loading…
Reference in New Issue
Block a user