From 37d572b261e0cb44a24616764e316957527aa7e7 Mon Sep 17 00:00:00 2001 From: syntron Date: Fri, 16 May 2025 19:50:11 +0200 Subject: [PATCH 1/2] [ModelicaSystem] add missing 'raise' keywords for exceptions --- OMPython/ModelicaSystem.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index 1ee8b993..4cb355d6 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -286,7 +286,7 @@ def _run_cmd(self, cmd: list, timeout: Optional[int] = None): # set the process environment from the generated .bat file in windows which should have all the dependencies batFilePath = pathlib.Path(self.tempdir) / f"{self.modelName}.bat" if not batFilePath.exists(): - ModelicaSystemError("Batch file (*.bat) does not exist " + str(batFilePath)) + raise ModelicaSystemError("Batch file (*.bat) does not exist " + str(batFilePath)) with open(batFilePath, 'r') as file: for line in file: @@ -351,7 +351,7 @@ def requestApi(self, apiName, entity=None, properties=None): # 2 def xmlparse(self): if not self.xmlFile.exists(): - ModelicaSystemError(f"XML file not generated: {self.xmlFile}") + raise ModelicaSystemError(f"XML file not generated: {self.xmlFile}") tree = ET.parse(self.xmlFile) rootCQ = tree.getroot() @@ -907,11 +907,11 @@ def checkValidInputs(self, name): if isinstance(l, tuple): # if l[0] < float(self.simValuesList[0]): if l[0] < float(self.simulateOptions["startTime"]): - ModelicaSystemError('Input time value is less than simulation startTime') + raise ModelicaSystemError('Input time value is less than simulation startTime') if len(l) != 2: - ModelicaSystemError(f'Value for {l} is in incorrect format!') + raise ModelicaSystemError(f'Value for {l} is in incorrect format!') else: - ModelicaSystemError('Error!!! Value must be in tuple format') + raise ModelicaSystemError('Error!!! Value must be in tuple format') def createCSVData(self) -> pathlib.Path: start_time: float = float(self.simulateOptions["startTime"]) From 0d67eeccfe34540cf6bdf50fc9d32cf5e8393d6e Mon Sep 17 00:00:00 2001 From: syntron Date: Fri, 16 May 2025 20:53:13 +0200 Subject: [PATCH 2/2] update tests --- tests/test_ModelicaSystem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_ModelicaSystem.py b/tests/test_ModelicaSystem.py index 9a0ce1c9..145aa526 100644 --- a/tests/test_ModelicaSystem.py +++ b/tests/test_ModelicaSystem.py @@ -360,13 +360,13 @@ def test_simulate_inputs(self): assert np.isclose(y[-1], 1.0) # let's try some edge cases - mod.setInputs("u1=[(-0.5, 0.0), (1.0, 1)]") # unmatched startTime with self.assertRaises(OMPython.ModelicaSystemError): + mod.setInputs("u1=[(-0.5, 0.0), (1.0, 1)]") mod.simulate() # unmatched stopTime - mod.setInputs("u1=[(0.0, 0.0), (0.5, 1)]") with self.assertRaises(OMPython.ModelicaSystemError): + mod.setInputs("u1=[(0.0, 0.0), (0.5, 1)]") mod.simulate() # Let's use both inputs, but each one with different number of of