From 0f078fb4957169cc8f6e63b05fbf4d6eeffc0f94 Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Fri, 3 Oct 2025 13:09:17 -0700 Subject: [PATCH 1/2] Added test whether pure function calls impure function For #607 --- buildingspy/CHANGES.txt | 8 ++++++++ buildingspy/VERSION | 2 +- .../development/error_dictionary_openmodelica.py | 5 +++++ .../test_development_regressiontest_openmodelica.py | 11 ++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/buildingspy/CHANGES.txt b/buildingspy/CHANGES.txt index 5ae70327..548d5d13 100644 --- a/buildingspy/CHANGES.txt +++ b/buildingspy/CHANGES.txt @@ -1,6 +1,14 @@ BuildingsPy Changelog --------------------- + +Version 5.2.1, ... +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- In buildingspy/development/regressiontest.py, added test for OpenModelica CI testing + that issues an error if a pure function calls an impure function. + (https://github.com/lbl-srg/BuildingsPy/issues/607) + Version 5.2.0, March 14, 2025 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/buildingspy/VERSION b/buildingspy/VERSION index 91ff5727..26d99a28 100644 --- a/buildingspy/VERSION +++ b/buildingspy/VERSION @@ -1 +1 @@ -5.2.0 +5.2.1 diff --git a/buildingspy/development/error_dictionary_openmodelica.py b/buildingspy/development/error_dictionary_openmodelica.py index 8f74f5ab..d82f0a00 100644 --- a/buildingspy/development/error_dictionary_openmodelica.py +++ b/buildingspy/development/error_dictionary_openmodelica.py @@ -39,3 +39,8 @@ def __init__(self): 'tool_message': "Non-array modification", 'counter': 0, 'summary_message': "Number of models with missing 'each' : {}\n"} + + self._error_dict["pure calling impure function"] = { + 'tool_message': "call to impure function", + 'counter': 0, + 'summary_message': "Number of models in which pure function calls impure function: {}\n"} \ No newline at end of file diff --git a/buildingspy/tests/test_development_regressiontest_openmodelica.py b/buildingspy/tests/test_development_regressiontest_openmodelica.py index 7a96e71c..34edfe6c 100644 --- a/buildingspy/tests/test_development_regressiontest_openmodelica.py +++ b/buildingspy/tests/test_development_regressiontest_openmodelica.py @@ -319,7 +319,16 @@ def test_regressiontest_diagnostics(self): 'mo_content': """Real x(start=0); equation Modelica.Math.exp(x)=-1;""", - 'description': "Model that has no solution."} + 'description': "Model that has no solution."}, + {'ret_val': 1, + 'mo_content': """ + function aPureFunction + algorithm + Modelica.Utilities.Streams.print("Hello"); + end aPureFunction; +equation + aPureFunction();""", + 'description': "Model in which a pure function calls an impure function."} ] # Run all test cases for test in tests: From c4237c5432b81bcc940d9f10ba27dbd95182d20a Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Fri, 3 Oct 2025 13:31:45 -0700 Subject: [PATCH 2/2] Added test for optimica --- buildingspy/CHANGES.txt | 4 ++-- buildingspy/development/error_dictionary_optimica.py | 6 ++++++ .../tests/test_development_regressiontest_optimica.py | 11 ++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/buildingspy/CHANGES.txt b/buildingspy/CHANGES.txt index 548d5d13..6797b918 100644 --- a/buildingspy/CHANGES.txt +++ b/buildingspy/CHANGES.txt @@ -5,8 +5,8 @@ BuildingsPy Changelog Version 5.2.1, ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- In buildingspy/development/regressiontest.py, added test for OpenModelica CI testing - that issues an error if a pure function calls an impure function. +- In buildingspy/development/regressiontest.py, added test for OpenModelica and + OPTIMICA CI testing that issues an error if a pure function calls an impure function. (https://github.com/lbl-srg/BuildingsPy/issues/607) Version 5.2.0, March 14, 2025 diff --git a/buildingspy/development/error_dictionary_optimica.py b/buildingspy/development/error_dictionary_optimica.py index ac81a5d7..48f5ab8e 100644 --- a/buildingspy/development/error_dictionary_optimica.py +++ b/buildingspy/development/error_dictionary_optimica.py @@ -78,3 +78,9 @@ def __init__(self): 'tool_message': "Integer, using Real instead", 'counter': 0, 'summary_message': "Number of models with too large Integers : {}\n"} + + # Check for pure function calling impure function + self._error_dict["pure calling impure function"] = { + 'tool_message': "Call to impure function", + 'counter': 0, + 'summary_message': "Number of models in which pure function calls impure function: {}\n"} \ No newline at end of file diff --git a/buildingspy/tests/test_development_regressiontest_optimica.py b/buildingspy/tests/test_development_regressiontest_optimica.py index 5a596a3f..388ae057 100644 --- a/buildingspy/tests/test_development_regressiontest_optimica.py +++ b/buildingspy/tests/test_development_regressiontest_optimica.py @@ -143,7 +143,16 @@ def test_regressiontest_diagnostics(self): 'mo_content': """Real x(start=0); equation Modelica.Math.exp(x)=-1;""", - 'description': "Model that has no solution."} + 'description': "Model that has no solution."}, + {'ret_val': 1, + 'mo_content': """ + function aPureFunction + algorithm + Modelica.Utilities.Streams.print("Hello"); + end aPureFunction; +equation + aPureFunction();""", + 'description': "Model in which a pure function calls an impure function."} ] # Run all test cases for test in tests: