Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable creation of new reference results in batch mode #561

Merged
merged 11 commits into from
Jun 21, 2024
18 changes: 14 additions & 4 deletions buildingspy/development/regressiontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def __init__(
self._statistics_log = "statistics.json"
self._nPro = multiprocessing.cpu_count()
self._batch = False
self._createNewReferenceResultsInBatchMode = False
self._pedanticModelica = False

# Number of data points that are used
Expand Down Expand Up @@ -510,15 +511,18 @@ def showGUI(self, show=True):
self._showGUI = show
return

def batchMode(self, batchMode):
def batchMode(self, batchMode, createNewReferenceResultsInBatchMode: bool = False):
""" Set the batch mode flag.

:param batchMode: Set to ``True`` to run without interactive prompts
and without plot windows.
:param createNewReferenceResultsInBatchMode: Set to ``True`` to create
new results in batch mode. Default is False.

By default, the regression tests require the user to respond if results differ from previous simulations.
This method can be used to run the script in batch mode, suppressing all prompts that require
the user to enter a response. If run in batch mode, no new results will be stored.
the user to enter a response.
By default, if run in batch mode, no new results will be stored.
To run the regression tests in batch mode, enter

>>> import os
Expand All @@ -529,6 +533,7 @@ def batchMode(self, batchMode):

"""
self._batch = batchMode
self._createNewReferenceResultsInBatchMode = createNewReferenceResultsInBatchMode

def pedanticModelica(self, pedanticModelica):
""" Set the pedantic Modelica mode flag.
Expand Down Expand Up @@ -2814,8 +2819,13 @@ def _checkReferencePoints(self, ans):
noOldResults = noOldResults + list(pai.keys())

if self._batch:
self._reporter.writeError(
f"Reference file {refFilNam} does not yet exist. You need to generate it by running tests in non-batch mode.")
if self._createNewReferenceResultsInBatchMode:
updateReferenceData = True
else:
self._reporter.writeError(
f"Reference file {refFilNam} does not yet exist. "
f"You need to generate it by running tests in non-batch mode."
)

if not (self._batch or ans == "Y" or ans == "N"):
if t_ref is None:
Expand Down