@@ -34,9 +34,9 @@ def test_setParameters():
3434 model_path = omc .sendExpression ("getInstallationDirectoryPath()" ) + "/share/doc/omc/testmodels/"
3535 mod = OMPython .ModelicaSystem (model_path + "BouncingBall.mo" , "BouncingBall" )
3636
37- # method 1
38- mod .setParameters (pvals = { "e" : 1.234 } )
39- mod .setParameters (pvals = { "g" : 321.0 } )
37+ # method 1 (test depreciated variants)
38+ mod .setParameters ("e= 1.234" )
39+ mod .setParameters ([ "g= 321.0" ] )
4040 assert mod .getParameters ("e" ) == ["1.234" ]
4141 assert mod .getParameters ("g" ) == ["321.0" ]
4242 assert mod .getParameters () == {
@@ -46,8 +46,9 @@ def test_setParameters():
4646 with pytest .raises (KeyError ):
4747 mod .getParameters ("thisParameterDoesNotExist" )
4848
49- # method 2
50- mod .setParameters (pvals = {"e" : 21.3 , "g" : 0.12 })
49+ # method 2 (new style)
50+ pvals = {"e" : 21.3 , "g" : 0.12 }
51+ mod .setParameters (** pvals )
5152 assert mod .getParameters () == {
5253 "e" : "21.3" ,
5354 "g" : "0.12" ,
@@ -64,8 +65,8 @@ def test_setSimulationOptions():
6465 mod = OMPython .ModelicaSystem (fileName = model_path + "BouncingBall.mo" , modelName = "BouncingBall" )
6566
6667 # method 1
67- mod .setSimulationOptions (simOptions = { " stopTime" : 1.234 } )
68- mod .setSimulationOptions (simOptions = { " tolerance" : 1.1e-08 } )
68+ mod .setSimulationOptions (stopTime = 1.234 )
69+ mod .setSimulationOptions (tolerance = 1.1e-08 )
6970 assert mod .getSimulationOptions ("stopTime" ) == ["1.234" ]
7071 assert mod .getSimulationOptions ("tolerance" ) == ["1.1e-08" ]
7172 assert mod .getSimulationOptions (["tolerance" , "stopTime" ]) == ["1.1e-08" , "1.234" ]
@@ -77,7 +78,7 @@ def test_setSimulationOptions():
7778 mod .getSimulationOptions ("thisOptionDoesNotExist" )
7879
7980 # method 2
80- mod .setSimulationOptions (simOptions = { " stopTime" : 2.1 , " tolerance" : " 1.2e-08" } )
81+ mod .setSimulationOptions (stopTime = 2.1 , tolerance = 1.2e-08 )
8182 d = mod .getSimulationOptions ()
8283 assert d ["stopTime" ] == "2.1"
8384 assert d ["tolerance" ] == "1.2e-08"
@@ -105,7 +106,7 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
105106 tmpdir = tmp_path / "tmpdir1"
106107 tmpdir .mkdir ()
107108 m = OMPython .ModelicaSystem (filePath , "M" , customBuildDirectory = tmpdir )
108- assert m .getWorkDirectory ().resolve () == tmpdir .resolve ()
109+ assert pathlib . Path ( m .getWorkDirectory () ).resolve () == tmpdir .resolve ()
109110 result_file = tmpdir / "a.mat"
110111 assert not result_file .exists ()
111112 m .simulate (resultfile = "a.mat" )
@@ -119,7 +120,9 @@ def test_getSolutions(model_firstorder):
119120 a = - 1
120121 tau = - 1 / a
121122 stopTime = 5 * tau
122- mod .setSimulationOptions (simOptions = {"stopTime" : stopTime , "stepSize" : 0.1 , "tolerance" : 1e-8 })
123+
124+ simOptions = {"stopTime" : stopTime , "stepSize" : 0.1 , "tolerance" : 1e-8 }
125+ mod .setSimulationOptions (** simOptions )
123126 mod .simulate ()
124127
125128 x = mod .getSolutions ("x" )
@@ -298,7 +301,7 @@ def test_getters(tmp_path):
298301 x0 = 1.0
299302 x_analytical = - b / a + (x0 + b / a ) * np .exp (a * stopTime )
300303 dx_analytical = (x0 + b / a ) * a * np .exp (a * stopTime )
301- mod .setSimulationOptions (simOptions = { " stopTime" : stopTime } )
304+ mod .setSimulationOptions (stopTime = stopTime )
302305 mod .simulate ()
303306
304307 # getOutputs after simulate()
@@ -327,7 +330,7 @@ def test_getters(tmp_path):
327330 mod .getContinuous ("a" ) # a is a parameter
328331
329332 with pytest .raises (OMPython .ModelicaSystemError ):
330- mod .setSimulationOptions (simOptions = { " thisOptionDoesNotExist" : 3 } )
333+ mod .setSimulationOptions (thisOptionDoesNotExist = 3 )
331334
332335
333336def test_simulate_inputs (tmp_path ):
@@ -345,7 +348,8 @@ def test_simulate_inputs(tmp_path):
345348""" )
346349 mod = OMPython .ModelicaSystem (fileName = model_file .as_posix (), modelName = "M_input" )
347350
348- mod .setSimulationOptions (simOptions = {"stopTime" : 1.0 })
351+ simOptions = {"stopTime" : 1.0 }
352+ mod .setSimulationOptions (** simOptions )
349353
350354 # integrate zero (no setInputs call) - it should default to None -> 0
351355 assert mod .getInputs () == {
@@ -357,7 +361,7 @@ def test_simulate_inputs(tmp_path):
357361 assert np .isclose (y [- 1 ], 0.0 )
358362
359363 # integrate a constant
360- mod .setInputs (name = { "u1" : 2.5 } )
364+ mod .setInputs (u1 = 2.5 )
361365 assert mod .getInputs () == {
362366 "u1" : [
363367 (0.0 , 2.5 ),
@@ -374,7 +378,8 @@ def test_simulate_inputs(tmp_path):
374378 assert np .isclose (y [- 1 ], 2.5 )
375379
376380 # now let's integrate the sum of two ramps
377- mod .setInputs (name = {"u1" : [(0.0 , 0.0 ), (0.5 , 2 ), (1.0 , 0 )]})
381+ inputs = {"u1" : [(0.0 , 0.0 ), (0.5 , 2 ), (1.0 , 0 )]}
382+ mod .setInputs (** inputs )
378383 assert mod .getInputs ("u1" ) == [[
379384 (0.0 , 0.0 ),
380385 (0.5 , 2.0 ),
@@ -387,17 +392,20 @@ def test_simulate_inputs(tmp_path):
387392 # let's try some edge cases
388393 # unmatched startTime
389394 with pytest .raises (OMPython .ModelicaSystemError ):
390- mod .setInputs (name = { "u1" : [(- 0.5 , 0.0 ), (1.0 , 1 )]} )
395+ mod .setInputs (u1 = [(- 0.5 , 0.0 ), (1.0 , 1 )])
391396 mod .simulate ()
392397 # unmatched stopTime
393398 with pytest .raises (OMPython .ModelicaSystemError ):
394- mod .setInputs (name = { "u1" : [(0.0 , 0.0 ), (0.5 , 1 )]} )
399+ mod .setInputs (u1 = [(0.0 , 0.0 ), (0.5 , 1 )])
395400 mod .simulate ()
396401
397402 # Let's use both inputs, but each one with different number of
398403 # samples. This has an effect when generating the csv file.
399- mod .setInputs (name = {"u1" : [(0.0 , 0 ), (1.0 , 1 )],
400- "u2" : [(0.0 , 0 ), (0.25 , 0.5 ), (0.5 , 1.0 ), (1.0 , 0 )]})
404+ inputs = {
405+ "u1" : [(0.0 , 0 ), (1.0 , 1 )],
406+ "u2" : [(0.0 , 0 ), (0.25 , 0.5 ), (0.5 , 1.0 ), (1.0 , 0 )],
407+ }
408+ mod .setInputs (** inputs )
401409 csv_file = mod ._createCSVData ()
402410 assert pathlib .Path (csv_file ).read_text () == """time,u1,u2,end
4034110.0,0.0,0.0,0
0 commit comments