Skip to content

Commit

Permalink
Move reference directory definition to init
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusfuchs committed Nov 18, 2020
1 parent 954f235 commit 970954b
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions buildingspy/development/regressiontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ class Tester(object):
considered as an absolute tolerance along y axis (and x axis if comp_tool='funnel'). If a dict
is provided, keys must be ('ax', 'ay') for absolute tolerance or ('rx', 'ry') for relative tolerance.
:param skip_verification: boolean (default ``False``).
If ``True``, unit test results are not verified against reference points.
If ``True``, unit test results are not verified against reference points.
:param dir_ref: str (default ``None``).
Base directory of reference results. For the default, the directory is
searched for or created within the library being tested at
``self._libHome\\Resources\\ReferenceResults\\Dymola``
This class can be used to run all regression tests.
Expand Down Expand Up @@ -230,6 +234,7 @@ def __init__(
comp_tool='funnel',
tol=1E-3,
skip_verification=False,
dir_ref=None,
):
""" Constructor."""
if tool == 'optimica':
Expand All @@ -251,6 +256,16 @@ def __init__(
self._libHome = os.path.abspath(".")
self._rootPackage = os.path.join(self._libHome, 'Resources', 'Scripts', 'Dymola')

# Set the reference results directory
if dir_ref is None:
self.dir_ref = os.path.join(
self._libHome, 'Resources', 'ReferenceResults', 'Dymola'
)
else:
self.dir_ref = dir_ref
if not os.path.exists(self.dir_ref):
os.makedirs(self.dir_ref)

# Set the tool
if tool in ['dymola', 'omc', 'optimica', 'jmodelica']:
self._modelica_tool = tool
Expand Down Expand Up @@ -2240,13 +2255,6 @@ def _check_fmu_statistics(self, ans):
import buildingspy.fmi as fmi

retVal = 0
# Check if the directory
# "self._libHome\\Resources\\ReferenceResults\\Dymola" exists, if not
# create it.
refDir = os.path.join(self._libHome, 'Resources', 'ReferenceResults', 'Dymola')
if not os.path.exists(refDir):
os.makedirs(refDir)

for data in self._data:
# Name of the reference file, which is the same as that matlab file name but with another extension.
# Only check data for FMU exort.
Expand All @@ -2263,7 +2271,7 @@ def _check_fmu_statistics(self, ans):
# Compare it with the stored results, and update the stored results if
# needed and requested by the user.
[updated_reference_data, ans] = self._compare_and_rewrite_fmu_dependencies(
dep_new, refDir, refFilNam, ans)
dep_new, self.dir_ref, refFilNam, ans)
# Reset answer, unless it is set to Y or N
if not (ans == "Y" or ans == "N"):
ans = "-"
Expand Down Expand Up @@ -2453,12 +2461,6 @@ def _checkReferencePoints(self, ans):
case of wrong simulation results, this function also returns ``0``, as this is
not considered an error in executing this function.
"""
# Check if the directory
# "self._libHome\\Resources\\ReferenceResults\\Dymola" exists, if not
# create it.
refDir = os.path.join(self._libHome, 'Resources', 'ReferenceResults', 'Dymola')
if not os.path.exists(refDir):
os.makedirs(refDir)

ret_val = 0
for data_idx, data in enumerate(self._data):
Expand Down Expand Up @@ -2529,7 +2531,7 @@ def _checkReferencePoints(self, ans):
ans = "-"
updateReferenceData = False
# check if reference results already exist in library
oldRefFulFilNam = os.path.join(refDir, refFilNam)
oldRefFulFilNam = os.path.join(self.dir_ref, refFilNam)
# If the reference file exists, and if the reference file contains
# results, compare the results.
if os.path.exists(oldRefFulFilNam):
Expand Down

0 comments on commit 970954b

Please sign in to comment.