Skip to content

Commit 97ded58

Browse files
committed
[ModelicaSystem] add ModelicaSystemError() for unhandled final else cases
there are a lot of functions which check the type of the input; this is done by if ... elif ... - however, invalid input is not catched, i.e. there is *NO* return value define (would be None) if the input is not matching any of the if branches
1 parent 1beeada commit 97ded58

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

OMPython/ModelicaSystem.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ def getQuantities(self, names=None): # 3
393393
elif isinstance(names, list):
394394
return [x for y in names for x in self.quantitiesList if x["name"] == y]
395395

396+
raise ModelicaSystemError("Unhandled input for getQuantities()")
397+
396398
def getContinuous(self, names=None): # 4
397399
"""
398400
This method returns dict. The key is continuous names and value is corresponding continuous value.
@@ -437,6 +439,8 @@ def getContinuous(self, names=None): # 4
437439
raise ModelicaSystemError(f"OM error: {i} is not continuous")
438440
return valuelist
439441

442+
raise ModelicaSystemError("Unhandled input for getContinous()")
443+
440444
def getParameters(self, names=None): # 5
441445
"""
442446
This method returns dict. The key is parameter names and value is corresponding parameter value.
@@ -453,6 +457,8 @@ def getParameters(self, names=None): # 5
453457
elif isinstance(names, list):
454458
return ([self.paramlist.get(x, "NotExist") for x in names])
455459

460+
raise ModelicaSystemError("Unhandled input for getParameters()")
461+
456462
def getlinearParameters(self, names=None): # 5
457463
"""
458464
This method returns dict. The key is parameter names and value is corresponding parameter value.
@@ -479,6 +485,8 @@ def getInputs(self, names=None): # 6
479485
elif isinstance(names, list):
480486
return ([self.inputlist.get(x, "NotExist") for x in names])
481487

488+
raise ModelicaSystemError("Unhandled input for getInputs()")
489+
482490
def getOutputs(self, names=None): # 7
483491
"""
484492
This method returns dict. The key is output names and value is corresponding output value.
@@ -519,6 +527,8 @@ def getOutputs(self, names=None): # 7
519527
return (i, "is not Output")
520528
return valuelist
521529

530+
raise ModelicaSystemError("Unhandled input for getOutputs()")
531+
522532
def getSimulationOptions(self, names=None): # 8
523533
"""
524534
This method returns dict. The key is simulation option names and value is corresponding simulation option value.
@@ -535,6 +545,8 @@ def getSimulationOptions(self, names=None): # 8
535545
elif isinstance(names, list):
536546
return ([self.simulateOptions.get(x, "NotExist") for x in names])
537547

548+
raise ModelicaSystemError("Unhandled input for getSimulationOptions()")
549+
538550
def getLinearizationOptions(self, names=None): # 9
539551
"""
540552
This method returns dict. The key is linearize option names and value is corresponding linearize option value.
@@ -551,6 +563,8 @@ def getLinearizationOptions(self, names=None): # 9
551563
elif isinstance(names, list):
552564
return ([self.linearOptions.get(x, "NotExist") for x in names])
553565

566+
raise ModelicaSystemError("Unhandled input for getLinearizationOptions()")
567+
554568
def getOptimizationOptions(self, names=None): # 10
555569
"""
556570
usage:
@@ -565,6 +579,8 @@ def getOptimizationOptions(self, names=None): # 10
565579
elif isinstance(names, list):
566580
return ([self.optimizeOptions.get(x, "NotExist") for x in names])
567581

582+
raise ModelicaSystemError("Unhandled input for getOptimizationOptions()")
583+
568584
def get_exe_file(self) -> pathlib.Path:
569585
"""Get path to model executable."""
570586
if platform.system() == "Windows":
@@ -687,12 +703,16 @@ def getSolutions(self, varList=None, resultfile=None): # 12
687703
self.sendExpression("closeSimulationResultFile()")
688704
return npRes
689705

706+
raise ModelicaSystemError("Unhandled input for getSolutions()")
707+
690708
def strip_space(self, name):
691709
if isinstance(name, str):
692710
return name.replace(" ", "")
693711
elif isinstance(name, list):
694712
return [x.replace(" ", "") for x in name]
695713

714+
raise ModelicaSystemError("Unhandled input for strip_space()")
715+
696716
def setMethodHelper(self, args1, args2, args3, args4=None):
697717
"""
698718
Helper function for setParameter(),setContinuous(),setSimulationOptions(),setLinearizationOption(),setOptimizationOption()

0 commit comments

Comments
 (0)