Skip to content

Commit 1edd4e8

Browse files
authored
[ModelicaSystem] reorder input (mypy) (#294)
* [ModelicaSystem] fix mypy warnings - fix reorder of inputs * define modelName as first (required!) argument * use *kwargs in tests * [ModelicaSystem] fix mypy warnings - update it to a backward compatible solution
1 parent b16c9d3 commit 1edd4e8

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

OMPython/ModelicaSystem.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, str]]]:
314314
class ModelicaSystem:
315315
def __init__(
316316
self,
317-
fileName: Optional[str | os.PathLike] = None,
317+
fileName: Optional[str | os.PathLike | pathlib.Path] = None,
318318
modelName: Optional[str] = None,
319319
lmodel: Optional[list[str | tuple[str, str]]] = None,
320320
commandLineOptions: Optional[str] = None,
@@ -360,9 +360,13 @@ def __init__(
360360
mod = ModelicaSystem("ModelicaModel.mo", "modelName", ["Modelica"])
361361
mod = ModelicaSystem("ModelicaModel.mo", "modelName", [("Modelica","3.2.3"), "PowerSystems"])
362362
"""
363+
363364
if fileName is None and modelName is None and not lmodel: # all None
364365
raise ModelicaSystemError("Cannot create ModelicaSystem object without any arguments")
365366

367+
if modelName is None:
368+
raise ModelicaSystemError("A modelname must be provided (argument modelName)!")
369+
366370
self.quantitiesList = []
367371
self.paramlist = {}
368372
self.inputlist = {}

tests/test_ModelicaSystem.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_setParameters():
5757
def test_setSimulationOptions():
5858
omc = OMPython.OMCSessionZMQ()
5959
model_path = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
60-
mod = OMPython.ModelicaSystem(model_path + "BouncingBall.mo", "BouncingBall")
60+
mod = OMPython.ModelicaSystem(fileName=model_path + "BouncingBall.mo", modelName="BouncingBall")
6161

6262
# method 1
6363
mod.setSimulationOptions("stopTime=1.234")
@@ -88,7 +88,7 @@ def test_relative_path(model_firstorder):
8888
model_relative = str(model_file)
8989
assert "/" not in model_relative
9090

91-
mod = OMPython.ModelicaSystem(model_relative, "M")
91+
mod = OMPython.ModelicaSystem(fileName=model_relative, modelName="M")
9292
assert float(mod.getParameters("a")[0]) == -1
9393
finally:
9494
model_file.unlink() # clean up the temporary file
@@ -145,7 +145,7 @@ def test_getters(tmp_path):
145145
y = der(x);
146146
end M_getters;
147147
""")
148-
mod = OMPython.ModelicaSystem(model_file.as_posix(), "M_getters")
148+
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="M_getters")
149149

150150
q = mod.getQuantities()
151151
assert isinstance(q, list)
@@ -324,7 +324,7 @@ def test_simulate_inputs(tmp_path):
324324
y = x;
325325
end M_input;
326326
""")
327-
mod = OMPython.ModelicaSystem(model_file.as_posix(), "M_input")
327+
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="M_input")
328328

329329
mod.setSimulationOptions("stopTime=1.0")
330330

tests/test_ModelicaSystemCmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def model_firstorder(tmp_path):
1616

1717

1818
def test_simflags(model_firstorder):
19-
mod = OMPython.ModelicaSystem(model_firstorder.as_posix(), "M")
19+
mod = OMPython.ModelicaSystem(fileName=model_firstorder.as_posix(), modelName="M")
2020
mscmd = OMPython.ModelicaSystemCmd(runpath=mod.tempdir, modelname=mod.modelName)
2121
mscmd.args_set({
2222
"noEventEmit": None,

tests/test_linearization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_getters(tmp_path):
5555
y2 = phi + u1;
5656
end Pendulum;
5757
""")
58-
mod = OMPython.ModelicaSystem(model_file.as_posix(), "Pendulum", ["Modelica"])
58+
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="Pendulum", lmodel=["Modelica"])
5959

6060
d = mod.getLinearizationOptions()
6161
assert isinstance(d, dict)

tests/test_optimization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_optimization_example(tmp_path):
3333
end BangBang2021;
3434
""")
3535

36-
mod = OMPython.ModelicaSystem(model_file.as_posix(), "BangBang2021")
36+
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="BangBang2021")
3737

3838
mod.setOptimizationOptions(["numberOfIntervals=16", "stopTime=1",
3939
"stepSize=0.001", "tolerance=1e-8"])

0 commit comments

Comments
 (0)