Skip to content

Commit 53bb6ff

Browse files
syntronadeas31
andauthored
[ModelicaSystem] add missing 'raise' keywords for exceptions (#286)
* [ModelicaSystem] add missing 'raise' keywords for exceptions * update tests --------- Co-authored-by: Adeel Asghar <adeel.asghar@liu.se>
1 parent 1fa4cfd commit 53bb6ff

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

OMPython/ModelicaSystem.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _run_cmd(self, cmd: list, timeout: Optional[int] = None):
286286
# set the process environment from the generated .bat file in windows which should have all the dependencies
287287
batFilePath = pathlib.Path(self.tempdir) / f"{self.modelName}.bat"
288288
if not batFilePath.exists():
289-
ModelicaSystemError("Batch file (*.bat) does not exist " + str(batFilePath))
289+
raise ModelicaSystemError("Batch file (*.bat) does not exist " + str(batFilePath))
290290

291291
with open(batFilePath, 'r') as file:
292292
for line in file:
@@ -351,7 +351,7 @@ def requestApi(self, apiName, entity=None, properties=None): # 2
351351

352352
def xmlparse(self):
353353
if not self.xmlFile.exists():
354-
ModelicaSystemError(f"XML file not generated: {self.xmlFile}")
354+
raise ModelicaSystemError(f"XML file not generated: {self.xmlFile}")
355355

356356
tree = ET.parse(self.xmlFile)
357357
rootCQ = tree.getroot()
@@ -907,11 +907,11 @@ def checkValidInputs(self, name):
907907
if isinstance(l, tuple):
908908
# if l[0] < float(self.simValuesList[0]):
909909
if l[0] < float(self.simulateOptions["startTime"]):
910-
ModelicaSystemError('Input time value is less than simulation startTime')
910+
raise ModelicaSystemError('Input time value is less than simulation startTime')
911911
if len(l) != 2:
912-
ModelicaSystemError(f'Value for {l} is in incorrect format!')
912+
raise ModelicaSystemError(f'Value for {l} is in incorrect format!')
913913
else:
914-
ModelicaSystemError('Error!!! Value must be in tuple format')
914+
raise ModelicaSystemError('Error!!! Value must be in tuple format')
915915

916916
def createCSVData(self) -> pathlib.Path:
917917
start_time: float = float(self.simulateOptions["startTime"])

tests/test_ModelicaSystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ def test_simulate_inputs(self):
360360
assert np.isclose(y[-1], 1.0)
361361

362362
# let's try some edge cases
363-
mod.setInputs("u1=[(-0.5, 0.0), (1.0, 1)]")
364363
# unmatched startTime
365364
with self.assertRaises(OMPython.ModelicaSystemError):
365+
mod.setInputs("u1=[(-0.5, 0.0), (1.0, 1)]")
366366
mod.simulate()
367367
# unmatched stopTime
368-
mod.setInputs("u1=[(0.0, 0.0), (0.5, 1)]")
369368
with self.assertRaises(OMPython.ModelicaSystemError):
369+
mod.setInputs("u1=[(0.0, 0.0), (0.5, 1)]")
370370
mod.simulate()
371371

372372
# Let's use both inputs, but each one with different number of of

0 commit comments

Comments
 (0)