From 47b6912414a24250b4ccaad0842e110d1abbf275 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Fri, 2 Oct 2026 16:08:34 +0200 Subject: [PATCH 1/2] Apply custom options alongside defaults options Added a flag to avoid adding default options --- OMPython/modelica_system_omc.py | 18 +++++++++++------- tests/test_ModelicaSystemOMC.py | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/OMPython/modelica_system_omc.py b/OMPython/modelica_system_omc.py index 8ee5c3b0..d7c4bf1a 100644 --- a/OMPython/modelica_system_omc.py +++ b/OMPython/modelica_system_omc.py @@ -39,13 +39,15 @@ def __init__( work_directory: Optional[str | os.PathLike] = None, omhome: Optional[str] = None, session: Optional[OMSessionABC] = None, + use_default_command_line_options: bool = True, ) -> None: """Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo(). Args: command_line_options: List with extra command line options as elements. The list elements are - provided to omc via setCommandLineOptions(). If set, the default values will be overridden. - To disable any command line options, use an empty list. + provided to omc via setCommandLineOptions() in addition to OMPython's default options. + use_default_command_line_options: Whether to set OMPython's default options for linearization. + Set to False to use only command_line_options, or no options if it is unspecified or empty. work_directory: Path to a directory to be used for temporary files like the model executable. If left unspecified, a tmp directory will be created. @@ -62,15 +64,17 @@ def __init__( work_directory=work_directory, ) - # set commandLineOptions using default values or the user defined list - if command_line_options is None: + options: list[str] = [] + if use_default_command_line_options: # set default command line options to improve the performance of linearization and to avoid recompilation if # the simulation executable is reused in linearize() via the runtime flag '-l' - command_line_options = [ + options.extend([ "--linearizationDumpLanguage=python", "--generateSymbolicLinearization", - ] - for opt in command_line_options: + ]) + if command_line_options is not None: + options.extend(command_line_options) + for opt in options: self.set_command_line_options(command_line_option=opt) def model( diff --git a/tests/test_ModelicaSystemOMC.py b/tests/test_ModelicaSystemOMC.py index 171db6b9..4015af1f 100644 --- a/tests/test_ModelicaSystemOMC.py +++ b/tests/test_ModelicaSystemOMC.py @@ -38,6 +38,30 @@ def model_firstorder(tmp_path, model_firstorder_content): return mod +@pytest.mark.parametrize( + ("use_defaults", "custom_options", "expected_options"), + [ + (True, ["--showAnnotations"], [ + "--linearizationDumpLanguage=python", + "--generateSymbolicLinearization", + "--showAnnotations", + ]), + (False, ["--showAnnotations"], ["--showAnnotations"]), + (False, [], []), + ], +) +def test_command_line_options(use_defaults, custom_options, expected_options): + session = OMPython.OMCSessionLocal() + mod = OMPython.ModelicaSystemOMC( + session=session, + command_line_options=custom_options, + use_default_command_line_options=use_defaults, + ) + + current_options = mod.sendExpression("getCommandLineOptions()") + assert current_options == expected_options + + def test_ModelicaSystem_loop(model_firstorder): def worker(): mod = OMPython.ModelicaSystemOMC() From 048dd156f6f97caa8e69fa6296d1c0aa9b603bb3 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Fri, 2 Oct 2026 16:21:24 +0200 Subject: [PATCH 2/2] Remove test --- tests/test_ModelicaSystemOMC.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/tests/test_ModelicaSystemOMC.py b/tests/test_ModelicaSystemOMC.py index 4015af1f..171db6b9 100644 --- a/tests/test_ModelicaSystemOMC.py +++ b/tests/test_ModelicaSystemOMC.py @@ -38,30 +38,6 @@ def model_firstorder(tmp_path, model_firstorder_content): return mod -@pytest.mark.parametrize( - ("use_defaults", "custom_options", "expected_options"), - [ - (True, ["--showAnnotations"], [ - "--linearizationDumpLanguage=python", - "--generateSymbolicLinearization", - "--showAnnotations", - ]), - (False, ["--showAnnotations"], ["--showAnnotations"]), - (False, [], []), - ], -) -def test_command_line_options(use_defaults, custom_options, expected_options): - session = OMPython.OMCSessionLocal() - mod = OMPython.ModelicaSystemOMC( - session=session, - command_line_options=custom_options, - use_default_command_line_options=use_defaults, - ) - - current_options = mod.sendExpression("getCommandLineOptions()") - assert current_options == expected_options - - def test_ModelicaSystem_loop(model_firstorder): def worker(): mod = OMPython.ModelicaSystemOMC()