From 970954bca6d2a49f95c524871d0b4f6fc40ca7a2 Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Wed, 18 Nov 2020 20:01:40 +0100 Subject: [PATCH 01/12] Move reference directory definition to init For #393 --- buildingspy/development/regressiontest.py | 34 ++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index add3bd58..0debe059 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -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. @@ -230,6 +234,7 @@ def __init__( comp_tool='funnel', tol=1E-3, skip_verification=False, + dir_ref=None, ): """ Constructor.""" if tool == 'optimica': @@ -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 @@ -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. @@ -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 = "-" @@ -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): @@ -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): From 707869c22a1a225ee2798c423f5be56ab1f97033 Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Wed, 18 Nov 2020 20:12:05 +0100 Subject: [PATCH 02/12] Move default dir_ref and folder creation This needs to happen after setting the library root, not in init. For #393 --- buildingspy/development/regressiontest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index 0debe059..c29411dd 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -257,14 +257,7 @@ def __init__( 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) + self.dir_ref = dir_ref # Set the tool if tool in ['dymola', 'omc', 'optimica', 'jmodelica']: @@ -437,6 +430,13 @@ def setLibraryRoot(self, rootDir): self._rootPackage = os.path.join(self._libHome, 'Resources', 'Scripts', 'Dymola') self.isValidLibrary(self._libHome) + if self.dir_ref is None: + self.dir_ref = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', 'Dymola' + ) + if not os.path.exists(self.dir_ref): + os.makedirs(self.dir_ref) + def useExistingResults(self, dirs): """ This function allows to use existing results, as opposed to running a simulation. From 0cc6b950e7239b6b788560b1093199164f5bc4d0 Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Wed, 18 Nov 2020 20:25:34 +0100 Subject: [PATCH 03/12] Extract setup of reference directory to method For #393 --- buildingspy/development/regressiontest.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index c29411dd..8e305f42 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -430,6 +430,20 @@ def setLibraryRoot(self, rootDir): self._rootPackage = os.path.join(self._libHome, 'Resources', 'Scripts', 'Dymola') self.isValidLibrary(self._libHome) + self._set_up_reference_directory() + + + def _set_up_reference_directory(self): + """ Set up the directory for the reference results. + + During initialization, ``self.dir_ref`` is either set to the default ``None`` + or a custom directory path. For the default, the standard path at + ``self._libHome\\Resources\\ReferenceResults\\Dymola`` can only be set up after + ``self._libHome`` has been set. Otherwise, the originally passed custom + path is used. In both cases, the directory is created if it does not exist, + yet. + """ + if self.dir_ref is None: self.dir_ref = os.path.join( self._libHome, 'Resources', 'ReferenceResults', 'Dymola' From f41a5ac7da0b0621954f0e8aded4f6cf4bed3b53 Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Fri, 20 Nov 2020 08:12:12 -0800 Subject: [PATCH 04/12] Refactored to allow tool cross comparison --- buildingspy/development/regressiontest.py | 125 +++++++++++++++------- 1 file changed, 88 insertions(+), 37 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index 8e305f42..aa62f810 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -124,10 +124,11 @@ class Tester(object): 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. - :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`` + :param base_reference_result_tool: {``dymola``, ``omc``, ``optimica``, ``jmodelica``}. + Default is ``None``. + :param base_reference_result_directory: str (default ``None``). + If not ``None``, usedd as directory of reference results for the base case. + This class can be used to run all regression tests. @@ -224,6 +225,24 @@ class Tester(object): which is read from the `.mo` file. However, with `rtol`, this value can be overwritten. Note that this syntax is still experimental and may be changed. + + + *Comparison against reference results from another tool* + + By default, the reference results from the current ``tool`` will be used. + To use reference results from another tool or from a specific directory, + set either ``base_reference_result_tool`` or ``base_reference_result_directory``. + + - If ``base_reference_result_tool`` is set, then the reference results from + the current library found in ``Resources/ReferenceResults/${tool}`` will be used. + (Due to legacy code, if ``tool=dymola``, the results will be in ``Resources/ReferenceResults/Dymola``.) + - If ``base_reference_result_directory`` is set, then the reference results will be + read from that directory. + - If ``base_reference_result_tool`` and ``base_reference_result_directory`` are both + not ``None``, an error will be issued. + + For any setting, the new reference results will be written to ``Resources/ReferenceResults/${tool}``. + """ def __init__( @@ -234,7 +253,8 @@ def __init__( comp_tool='funnel', tol=1E-3, skip_verification=False, - dir_ref=None, + base_reference_result_tool=None, + base_reference_result_directory=None, ): """ Constructor.""" if tool == 'optimica': @@ -256,15 +276,27 @@ def __init__( self._libHome = os.path.abspath(".") self._rootPackage = os.path.join(self._libHome, 'Resources', 'Scripts', 'Dymola') - # Set the reference results directory - self.dir_ref = dir_ref - # Set the tool if tool in ['dymola', 'omc', 'optimica', 'jmodelica']: self._modelica_tool = tool else: raise ValueError( "Value of 'tool' of constructor 'Tester' must be 'dymola', 'omc', 'optimica' or 'jmodelica'. Received '{}'.".format(tool)) + + # Check the settings for the reference results + if base_reference_result_tool is not None and base_reference_result_directory is not None: + raise ValueError( + "Only one of the arguments 'base_reference_result_directory' and 'base_reference_result_directory' can be different from 'None'.") + + # Original value of argument. Used because setLibraryRoot can change the library name. + self._arg_base_reference_result_directory = base_reference_result_directory + self._arg_base_reference_result_tool = base_reference_result_tool + # Set the reference results directory + self._base_reference_result_directory = None + self._base_reference_result_tool = None + self._set_up_result_directories() + + # File to which the console output of the simulator is written self._simulator_log_file = "simulator-{}.log".format(tool) # File to which the console output of the simulator of failed simulations is written @@ -430,26 +462,35 @@ def setLibraryRoot(self, rootDir): self._rootPackage = os.path.join(self._libHome, 'Resources', 'Scripts', 'Dymola') self.isValidLibrary(self._libHome) - self._set_up_reference_directory() + self._set_up_result_directories() - def _set_up_reference_directory(self): - """ Set up the directory for the reference results. + def _set_up_result_directories(self): + """ Set up the directories for the reference results. - During initialization, ``self.dir_ref`` is either set to the default ``None`` - or a custom directory path. For the default, the standard path at - ``self._libHome\\Resources\\ReferenceResults\\Dymola`` can only be set up after - ``self._libHome`` has been set. Otherwise, the originally passed custom - path is used. In both cases, the directory is created if it does not exist, - yet. + This methods sets the directories for the base results and the target results, + e.g., the new reference results. + It also creates the directory for the target results if it does not yet exist. """ - if self.dir_ref is None: - self.dir_ref = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', 'Dymola' - ) - if not os.path.exists(self.dir_ref): - os.makedirs(self.dir_ref) + if self._arg_base_reference_result_directory is not None: + # If the base directory is specified, it must exist. + if not os.path.exists(self._arg_base_reference_result_directory): + raise IOError(f"Directory {self._arg_base_reference_result_directory} must exist. Check argument for 'base_reference_result_directory'.") + self._reference_results_base = self._arg_base_reference_result_directory + elif self._arg_base_reference_result_tool is not None: + if self._arg_base_reference_result_tool is "dymola": + self._reference_results_base = os.path.join(self._libHome, 'Resources', 'ReferenceResults', "Dymola") + else: + self._reference_results_base = os.path.join(self._libHome, 'Resources', 'ReferenceResults', self._arg_base_reference_result_tool) + + if self._modelica_tool is "dymola": + self._reference_results_target = os.path.join(self._libHome, 'Resources', 'ReferenceResults', "Dymola") + else: + self._reference_results_target = os.path.join(self._libHome, 'Resources', 'ReferenceResults', self._modelica_tool) + + if not os.path.exists(self._reference_results_target): + os.makedirs(self._reference_results_target) def useExistingResults(self, dirs): """ This function allows to use existing results, as opposed to running a simulation. @@ -2184,7 +2225,8 @@ def g(s): return s.replace(" ", "").split(",") def _compare_and_rewrite_fmu_dependencies( self, new_dependencies, - reference_file_path, + reference_file_path_base, + reference_file_path_target, reference_file_name, ans): """ Compares whether the ``.fmu`` dependencies have been changed. @@ -2193,26 +2235,29 @@ def _compare_and_rewrite_fmu_dependencies( If they differ from the reference results, it askes whether to accept the new ones. :param new_dependencies: A dictionary with the new dependencies. - :param reference_file_path: Path to the file with reference results. + :param reference_file_path_base: Path to the file with the old reference results. + :param reference_file_path_target: Path to the file with new reference results. :param reference_file_name: Name of the file with reference results. :param ans: A previously entered answer, either ``y``, ``Y``, ``n`` or ``N``. :return: A tuple consisting of a boolean ``updated_reference_data`` and the value of ``ans``. """ - # Absolute path to the reference file - abs_ref_fil_nam = os.path.join(reference_file_path, reference_file_name) + # Absolute path to the reference files + abs_ref_fil_nam_base = os.path.join(reference_file_path_base, reference_file_name) + abs_ref_fil_nam_target = os.path.join(reference_file_path_target, reference_file_name) + # Put dependencies in data format needed to write to the reference result file y_tra = dict() y_tra['fmu-dependencies'] = new_dependencies # Check whether the reference results exist. - if not os.path.exists(abs_ref_fil_nam): + if not os.path.exists(abs_ref_fil_nam_base): print("Warning ***: Reference file {} does not yet exist.".format(reference_file_name)) while not (ans == "n" or ans == "y" or ans == "Y" or ans == "N"): print(" Create new file?") ans = input(" Enter: y(yes), n(no), Y(yes for all), N(no for all): ") if ans == "y" or ans == "Y": - self._writeReferenceResults(abs_ref_fil_nam, None, y_tra) + self._writeReferenceResults(abs_ref_fil_nam_target, None, y_tra) self._reporter.writeOutput("Wrote new reference file %s." % reference_file_name) else: @@ -2221,7 +2266,7 @@ def _compare_and_rewrite_fmu_dependencies( return [True, ans] # The file that may contain the reference results exist. - old_dep = self._readReferenceResults(abs_ref_fil_nam) + old_dep = self._readReferenceResults(abs_ref_fil_nam_base) # Check whether it contains a key 'statistics-fmu-dependencies' if 'statistics-fmu-dependencies' in old_dep: # Compare the statistics for each section @@ -2236,7 +2281,7 @@ def _compare_and_rewrite_fmu_dependencies( print(" Rewrite file?") ans = input(" Enter: y(yes), n(no), Y(yes for all), N(no for all): ") if ans == "y" or ans == "Y": - self._writeReferenceResults(abs_ref_fil_nam, None, y_tra) + self._writeReferenceResults(abs_ref_fil_nam_target, None, y_tra) self._reporter.writeWarning( "*** Warning: Rewrote reference file %s due to new FMU statistics." % reference_file_name) @@ -2249,7 +2294,7 @@ def _compare_and_rewrite_fmu_dependencies( print(" Rewrite file?") ans = input(" Enter: y(yes), n(no), Y(yes for all), N(no for all): ") if ans == "y" or ans == "Y": - self._writeReferenceResults(abs_ref_fil_nam, None, y_tra) + self._writeReferenceResults(abs_ref_fil_nam_target, None, y_tra) self._reporter.writeWarning( "*** Warning: Rewrote reference file %s as the old one had no FMU statistics." % reference_file_name) @@ -2285,7 +2330,11 @@ 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, self.dir_ref, refFilNam, ans) + dep_new, + self._reference_results_base, + self._reference_results_target, + refFilNam, + ans) # Reset answer, unless it is set to Y or N if not (ans == "Y" or ans == "N"): ans = "-" @@ -2545,7 +2594,9 @@ def _checkReferencePoints(self, ans): ans = "-" updateReferenceData = False # check if reference results already exist in library - oldRefFulFilNam = os.path.join(self.dir_ref, refFilNam) + oldRefFulFilNam = os.path.join(self._reference_results_base, refFilNam) + newRefFulFilNam = os.path.join(self._reference_results_target, refFilNam) + # If the reference file exists, and if the reference file contains # results, compare the results. if os.path.exists(oldRefFulFilNam): @@ -2572,12 +2623,12 @@ def _checkReferencePoints(self, ans): updateReferenceData = True else: self._reporter.writeError("Did not write new reference file %s." % - oldRefFulFilNam) + newRefFulFilNam) if updateReferenceData: # If the reference data of any variable was updated # Make dictionary to save the results and the svn information - self._writeReferenceResults(oldRefFulFilNam, y_sim, y_tra) + self._writeReferenceResults(newRefFulFilNam, y_sim, y_tra) self._reporter.writeOutput("Wrote new reference file %s." % - oldRefFulFilNam) + newRefFulFilNam) else: # Tests that export FMUs do not have an output file. Hence, we do not warn From 351ac5906389cf1fd92f734b7101407a498e94b2 Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Fri, 20 Nov 2020 08:17:14 -0800 Subject: [PATCH 05/12] Run make pep8 PEP8_CORRECT_CODE=true --- buildingspy/development/regressiontest.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index aa62f810..5e09dbd9 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -286,7 +286,7 @@ def __init__( # Check the settings for the reference results if base_reference_result_tool is not None and base_reference_result_directory is not None: raise ValueError( - "Only one of the arguments 'base_reference_result_directory' and 'base_reference_result_directory' can be different from 'None'.") + "Only one of the arguments 'base_reference_result_directory' and 'base_reference_result_directory' can be different from 'None'.") # Original value of argument. Used because setLibraryRoot can change the library name. self._arg_base_reference_result_directory = base_reference_result_directory @@ -296,7 +296,6 @@ def __init__( self._base_reference_result_tool = None self._set_up_result_directories() - # File to which the console output of the simulator is written self._simulator_log_file = "simulator-{}.log".format(tool) # File to which the console output of the simulator of failed simulations is written @@ -464,7 +463,6 @@ def setLibraryRoot(self, rootDir): self._set_up_result_directories() - def _set_up_result_directories(self): """ Set up the directories for the reference results. @@ -476,18 +474,23 @@ def _set_up_result_directories(self): if self._arg_base_reference_result_directory is not None: # If the base directory is specified, it must exist. if not os.path.exists(self._arg_base_reference_result_directory): - raise IOError(f"Directory {self._arg_base_reference_result_directory} must exist. Check argument for 'base_reference_result_directory'.") + raise IOError( + f"Directory {self._arg_base_reference_result_directory} must exist. Check argument for 'base_reference_result_directory'.") self._reference_results_base = self._arg_base_reference_result_directory elif self._arg_base_reference_result_tool is not None: if self._arg_base_reference_result_tool is "dymola": - self._reference_results_base = os.path.join(self._libHome, 'Resources', 'ReferenceResults', "Dymola") + self._reference_results_base = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', "Dymola") else: - self._reference_results_base = os.path.join(self._libHome, 'Resources', 'ReferenceResults', self._arg_base_reference_result_tool) + self._reference_results_base = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', self._arg_base_reference_result_tool) if self._modelica_tool is "dymola": - self._reference_results_target = os.path.join(self._libHome, 'Resources', 'ReferenceResults', "Dymola") + self._reference_results_target = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', "Dymola") else: - self._reference_results_target = os.path.join(self._libHome, 'Resources', 'ReferenceResults', self._modelica_tool) + self._reference_results_target = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', self._modelica_tool) if not os.path.exists(self._reference_results_target): os.makedirs(self._reference_results_target) From 6c9bc383aeffd2799fcc35d995eefe0c709a8090 Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Fri, 20 Nov 2020 08:35:00 -0800 Subject: [PATCH 06/12] Addressed base case --- buildingspy/development/regressiontest.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index 5e09dbd9..f50a8e6d 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -292,8 +292,8 @@ def __init__( self._arg_base_reference_result_directory = base_reference_result_directory self._arg_base_reference_result_tool = base_reference_result_tool # Set the reference results directory - self._base_reference_result_directory = None - self._base_reference_result_tool = None + self._reference_results_base = None + self._reference_results_target = None self._set_up_result_directories() # File to which the console output of the simulator is written @@ -484,6 +484,13 @@ def _set_up_result_directories(self): else: self._reference_results_base = os.path.join( self._libHome, 'Resources', 'ReferenceResults', self._arg_base_reference_result_tool) + else: # Use the default setting. + if self._modelica_tool is "dymola": + self._reference_results_base = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', "Dymola") + else: + self._reference_results_base = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', self._modelica_tool) if self._modelica_tool is "dymola": self._reference_results_target = os.path.join( From aaa567c4020801af7b5799ebb12aa720940cf7b4 Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Fri, 20 Nov 2020 08:35:22 -0800 Subject: [PATCH 07/12] Run make pep8 PEP8_CORRECT_CODE=true --- buildingspy/development/regressiontest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index f50a8e6d..c1d0bcc9 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -484,7 +484,7 @@ def _set_up_result_directories(self): else: self._reference_results_base = os.path.join( self._libHome, 'Resources', 'ReferenceResults', self._arg_base_reference_result_tool) - else: # Use the default setting. + else: # Use the default setting. if self._modelica_tool is "dymola": self._reference_results_base = os.path.join( self._libHome, 'Resources', 'ReferenceResults', "Dymola") From cac060c3dbc26370ab551bf5d9238bae4dd77036 Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Tue, 1 Dec 2020 20:44:05 +0100 Subject: [PATCH 08/12] Typo --- buildingspy/development/regressiontest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index c1d0bcc9..a12d72e3 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -127,7 +127,7 @@ class Tester(object): :param base_reference_result_tool: {``dymola``, ``omc``, ``optimica``, ``jmodelica``}. Default is ``None``. :param base_reference_result_directory: str (default ``None``). - If not ``None``, usedd as directory of reference results for the base case. + If not ``None``, used as directory of reference results for the base case. This class can be used to run all regression tests. From 3af75a0300419b268a0a290e74d87d5a1fb85f2d Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Tue, 1 Dec 2020 20:58:55 +0100 Subject: [PATCH 09/12] Extract tool name processing to method For #393 --- buildingspy/development/regressiontest.py | 43 +++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index a12d72e3..2267f6da 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -478,30 +478,37 @@ def _set_up_result_directories(self): f"Directory {self._arg_base_reference_result_directory} must exist. Check argument for 'base_reference_result_directory'.") self._reference_results_base = self._arg_base_reference_result_directory elif self._arg_base_reference_result_tool is not None: - if self._arg_base_reference_result_tool is "dymola": - self._reference_results_base = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', "Dymola") - else: - self._reference_results_base = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', self._arg_base_reference_result_tool) + dir_tool = self._get_name_tool_directory(self._arg_base_reference_result_tool) + self._reference_results_base = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', dir_tool) else: # Use the default setting. - if self._modelica_tool is "dymola": - self._reference_results_base = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', "Dymola") - else: - self._reference_results_base = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', self._modelica_tool) + dir_tool = self._get_name_tool_directory(self._modelica_tool) + self._reference_results_base = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', dir_tool) - if self._modelica_tool is "dymola": - self._reference_results_target = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', "Dymola") - else: - self._reference_results_target = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', self._modelica_tool) + dir_tool = self._get_name_tool_directory(self._modelica_tool) + self._reference_results_target = os.path.join( + self._libHome, 'Resources', 'ReferenceResults', dir_tool) if not os.path.exists(self._reference_results_target): os.makedirs(self._reference_results_target) + def _get_name_tool_directory(self, name_tool): + """ Get the legacy-compatible directory name for selected tool. + + :param name_tool: str Name of the selected tool + + Result is lower case for all tools except for Dymola which is uppercase + due to legacy + """ + + if name_tool == "dymola": + result = "Dymola" + else: + result = name_tool + + return result + def useExistingResults(self, dirs): """ This function allows to use existing results, as opposed to running a simulation. From 575bf854adb31383358c888c3e545ee05ed58d94 Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Tue, 1 Dec 2020 21:02:08 +0100 Subject: [PATCH 10/12] Refactor conditional For #393 --- buildingspy/development/regressiontest.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index 2267f6da..e7108e1c 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -477,15 +477,14 @@ def _set_up_result_directories(self): raise IOError( f"Directory {self._arg_base_reference_result_directory} must exist. Check argument for 'base_reference_result_directory'.") self._reference_results_base = self._arg_base_reference_result_directory - elif self._arg_base_reference_result_tool is not None: - dir_tool = self._get_name_tool_directory(self._arg_base_reference_result_tool) + else: + if self._arg_base_reference_result_tool is not None: + dir_tool = self._get_name_tool_directory(self._arg_base_reference_result_tool) + else: + dir_tool = self._get_name_tool_directory(self._modelica_tool) self._reference_results_base = os.path.join( self._libHome, 'Resources', 'ReferenceResults', dir_tool) - else: # Use the default setting. - dir_tool = self._get_name_tool_directory(self._modelica_tool) - self._reference_results_base = os.path.join( - self._libHome, 'Resources', 'ReferenceResults', dir_tool) - + dir_tool = self._get_name_tool_directory(self._modelica_tool) self._reference_results_target = os.path.join( self._libHome, 'Resources', 'ReferenceResults', dir_tool) From c75ab45b204a208096665e43e6272c3045b9ccbb Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Tue, 1 Dec 2020 21:16:41 +0100 Subject: [PATCH 11/12] Add test for error too many settings For #393 --- buildingspy/tests/test_development_regressiontest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/buildingspy/tests/test_development_regressiontest.py b/buildingspy/tests/test_development_regressiontest.py index 28147bc2..fb6758ad 100644 --- a/buildingspy/tests/test_development_regressiontest.py +++ b/buildingspy/tests/test_development_regressiontest.py @@ -256,6 +256,16 @@ def test_expand_packages(self): self.assertRaises(ValueError, r.Tester.expand_packages, "AB}a{") + def test_invalid_custom_reference_results(self): + import buildingspy.development.regressiontest as r + # Verify that setting both options raises a ValueError. + args = [] + kwargs = { + "base_reference_result_tool": "dymola", + "base_reference_result_directory": "test/test" + } + self.assertRaises(ValueError, r.Tester, *args, **kwargs) + if __name__ == '__main__': unittest.main() From 907ba79b660d9d466916df2f86d1a02824700666 Mon Sep 17 00:00:00 2001 From: Marcus Fuchs Date: Tue, 1 Dec 2020 21:18:47 +0100 Subject: [PATCH 12/12] Add test for non-existing directory For #393 --- buildingspy/tests/test_development_regressiontest.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/buildingspy/tests/test_development_regressiontest.py b/buildingspy/tests/test_development_regressiontest.py index fb6758ad..f4ed884f 100644 --- a/buildingspy/tests/test_development_regressiontest.py +++ b/buildingspy/tests/test_development_regressiontest.py @@ -256,7 +256,7 @@ def test_expand_packages(self): self.assertRaises(ValueError, r.Tester.expand_packages, "AB}a{") - def test_invalid_custom_reference_results(self): + def test_conflicting_custom_reference_results_settings(self): import buildingspy.development.regressiontest as r # Verify that setting both options raises a ValueError. args = [] @@ -266,6 +266,15 @@ def test_invalid_custom_reference_results(self): } self.assertRaises(ValueError, r.Tester, *args, **kwargs) + def test_invalid_custom_reference_directory(self): + import buildingspy.development.regressiontest as r + # Verify that setting both options raises a ValueError. + args = [] + kwargs = { + "base_reference_result_directory": "test/test" + } + self.assertRaises(OSError, r.Tester, *args, **kwargs) + if __name__ == '__main__': unittest.main()