Skip to content

Commit

Permalink
Automatically generate result file name for Dymola regression tests (#…
Browse files Browse the repository at this point in the history
…447)

* Corrected wrong file suffix in error message

* Generated .mat files automatically

For #446

* Added missing package name
  • Loading branch information
mwetter authored Nov 30, 2021
1 parent 1e9c1b2 commit 1783a1e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
3 changes: 3 additions & 0 deletions buildingspy/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ BuildingsPy Changelog

Version 3.0.0, xxx, 2021 -- Release 3.0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- For unit tests, changed code to generate names of Dymola output file to ensure that they are unique.
Previously, an error was issued if they are not unique.
(https://github.com/lbl-srg/BuildingsPy/issues/446)
- For merge script, renamed set_excluded_packages to set_excluded_directories
(https://github.com/lbl-srg/BuildingsPy/issues/439)
- For Dymola simulations, corrected call to openModel in buildingspy/simulate/Dymola.py
Expand Down
2 changes: 1 addition & 1 deletion buildingspy/development/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def merge(self, overwrite_reference_results=False):
is_binary = True
break
if is_binary:
copyfile(srcFil, new_file)
shutil.copyfile(srcFil, new_file)
else:
self._copy_rename(self._src_library_name,
self._new_library_name,
Expand Down
41 changes: 30 additions & 11 deletions buildingspy/development/regressiontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,17 +1070,13 @@ def _get_attribute_value(line, keyword, dat):
if v_i not in dat['ResultVariables']:
dat['ResultVariables'].append(v_i)

# search for the result file
for lin in Lines:
if 'resultFile=\"' in lin:
matFil = re.search(
r'(?<=resultFile=\")[a-zA-Z0-9_\.]+', lin).group()
# Add the .mat extension as this is not included in the
# resultFile entry.
matFil = matFil + '.mat'
break

if self._modelica_tool == 'optimica' or self._modelica_tool == 'jmodelica':
# Create the result file name.
if self._modelica_tool == 'dymola':
# For Dymola, this is not the name in the .mos file (as these may not be unique).
# Rather, we set the result file name to be the mos file name with
# .mat extension
matFil = f"{dat['model_name']}.mat"
else:
matFil = '{}_result.mat'.format(
re.sub(r'\.', '_', dat['model_name']))

Expand Down Expand Up @@ -2858,6 +2854,28 @@ def _removePlotCommands(self, mosFilNam):
for i in range(len(linWri)):
filWri.write(lines[linWri[i]])

def _updateResultFile(self, mosFilNam, modelName):
"""
Update the mos script to use ``matFilNam`` as the name of the result file.
:param mosFilNam: The name of the ``*.mos`` file
:param modelName: The name of the model
This function updates in the ``mosFilNam`` the simulate command
to use `modelName.mat` as the result file name.
This ensures that each result file name is unique.
"""
import re
with open(mosFilNam, mode="r+", encoding="utf-8-sig") as fil:
con = fil.read()
count = 0
(conNew, count) = re.subn(r"resultFile\s*=\s*\"(.+)\"",
f"resultFile=\"{modelName}\"", con, count=count, flags=re.M)
# Models with translateModelFMU have no result file. So these files are not written to disk
if count > 0:
with open(mosFilNam, mode="w", encoding="utf-8-sig") as fil:
fil.write(conNew)

def _write_runscript_dymola(self, iPro):
"""Create the runAll.mos script for the current processor and for Dymola,
and return the number of generated regression tests.
Expand Down Expand Up @@ -3148,6 +3166,7 @@ def _print_end_of_json(isLastItem, fileHandle, logFileName):
print(
"****** {} neither requires a simulation nor an FMU export.".format(self._data[i]['ScriptFile']))
self._removePlotCommands(absMosFilNam)
self._updateResultFile(absMosFilNam, self._data[i]['model_name'])
nUniTes = nUniTes + 1
iItem = iItem + 1

Expand Down

0 comments on commit 1783a1e

Please sign in to comment.