mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4474 Add command for getting runtime info (i.e. console/gui)
* Also fixed up some tests when running in console
This commit is contained in:
@@ -23,4 +23,11 @@ class App:
|
||||
def versionString(self):
|
||||
return str(self.majorVersion()) + "." + str(self.minorVersion()) + "." + str(self.patchVersion())
|
||||
def exit(self):
|
||||
print("Telling ResInsight to Exit")
|
||||
return self.app.Exit(Empty())
|
||||
def isConsole(self):
|
||||
print("RunTimeInfo stuff: ", self.app.GetRuntimeInfo(Empty()).app_type)
|
||||
return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('CONSOLE_APPLICATION')
|
||||
def isGui(self):
|
||||
print("RunTimeInfo stuff: ", self.app.GetRuntimeInfo(Empty()).app_type)
|
||||
return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('GUI_APPLICATION')
|
||||
|
||||
@@ -13,6 +13,8 @@ from .Commands import Commands
|
||||
from .Project import Project
|
||||
|
||||
class Instance:
|
||||
launched = False
|
||||
|
||||
@staticmethod
|
||||
def is_port_in_use(port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
@@ -20,7 +22,7 @@ class Instance:
|
||||
return s.connect_ex(('localhost', port)) == 0
|
||||
|
||||
@staticmethod
|
||||
def launch(resInsightExecutable = ''):
|
||||
def launch(resInsightExecutable = '', console = False):
|
||||
port = 50051
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
@@ -38,9 +40,11 @@ class Instance:
|
||||
|
||||
print('Port ' + str(port))
|
||||
print('Trying to launch', resInsightExecutable)
|
||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, " --grpcserver " + str(port))
|
||||
print(pid)
|
||||
return Instance(port)
|
||||
parameters = " --grpcserver " + str(port)
|
||||
if console:
|
||||
parameters += " --console"
|
||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, parameters)
|
||||
return Instance(port=port, launched=True)
|
||||
|
||||
@staticmethod
|
||||
def find(startPort = 50051, endPort = 50071):
|
||||
@@ -56,10 +60,11 @@ class Instance:
|
||||
print('Error: Could not find any ResInsight instances responding between ports ' + str(startPort) + ' and ' + str(endPort))
|
||||
return None
|
||||
|
||||
def __init__(self, port = 50051):
|
||||
def __init__(self, port = 50051, launched = False):
|
||||
logging.basicConfig()
|
||||
location = "localhost:" + str(port)
|
||||
self.channel = grpc.insecure_channel(location)
|
||||
self.launched = launched
|
||||
|
||||
# Main version check package
|
||||
self.app = App(self.channel)
|
||||
@@ -77,4 +82,10 @@ class Instance:
|
||||
# Service packages
|
||||
self.commands = Commands(self.channel)
|
||||
self.project = Project(self.channel)
|
||||
|
||||
|
||||
path = os.getcwd()
|
||||
self.commands.setStartDir(path=path)
|
||||
|
||||
def __del__(self):
|
||||
if self.launched:
|
||||
self.app.exit()
|
||||
@@ -1,24 +1,28 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
import getopt
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
instance = rips.Instance.launch()
|
||||
|
||||
if (not instance):
|
||||
print("A ResInsight instance is required for running the tests")
|
||||
exit(1)
|
||||
_rips_instance = None
|
||||
|
||||
@pytest.fixture
|
||||
def rips_instance():
|
||||
return instance
|
||||
return _rips_instance
|
||||
|
||||
@pytest.fixture
|
||||
def initializeTest():
|
||||
instance.project.close()
|
||||
_rips_instance.project.close()
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
print("Telling ResInsight to Exit")
|
||||
instance.app.exit()
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--console", action="store_true", default=False, help="Run as console application")
|
||||
|
||||
def pytest_configure(config):
|
||||
global _rips_instance
|
||||
console = False
|
||||
if config.getoption('--console'):
|
||||
print("Should run as console app")
|
||||
console = True
|
||||
_rips_instance = rips.Instance.launch(console=console)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
@@ -8,6 +9,9 @@ import rips
|
||||
import dataroot
|
||||
|
||||
def test_exportSnapshots(rips_instance, initializeTest):
|
||||
if not rips_instance.app.isGui():
|
||||
pytest.skip("Cannot run test without a GUI")
|
||||
|
||||
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
rips_instance.project.loadCase(casePath)
|
||||
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||
|
||||
Reference in New Issue
Block a user