Skip to content

Commit 9c6f5bb

Browse files
committed
[ModelicaSystem] fix mypy warnings - fix reorder of inputs
* define modelName as first (required!) argument * use *kwargs in tests
1 parent b16c9d3 commit 9c6f5bb

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ 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,
318-
modelName: Optional[str] = None,
317+
modelName: str,
318+
fileName: Optional[str | os.PathLike | pathlib.Path] = None,
319319
lmodel: Optional[list[str | tuple[str, str]]] = None,
320320
commandLineOptions: Optional[str] = None,
321321
variableFilter: Optional[str] = None,
@@ -330,10 +330,10 @@ def __init__(
330330
xml files, etc.
331331
332332
Args:
333-
fileName: Path to the model file. Either absolute or relative to
334-
the current working directory.
335333
modelName: The name of the model class. If it is contained within
336334
a package, "PackageName.ModelName" should be used.
335+
fileName: Path to the model file. Either absolute or relative to
336+
the current working directory.
337337
lmodel: List of libraries to be loaded before the model itself is
338338
loaded. Two formats are supported for the list elements:
339339
lmodel=["Modelica"] for just the library name
@@ -421,7 +421,7 @@ def __init__(
421421
self.loadFile(fileName=self.fileName)
422422

423423
# allow directly loading models from MSL without fileName
424-
elif fileName is None and modelName is not None:
424+
else:
425425
self.loadLibrary(lmodel=self.lmodel)
426426

427427
if build:

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=self.model.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)