diff --git a/buildingspy/CHANGES.txt b/buildingspy/CHANGES.txt index 5ae70327..8a3f91c7 100644 --- a/buildingspy/CHANGES.txt +++ b/buildingspy/CHANGES.txt @@ -1,6 +1,12 @@ BuildingsPy Changelog --------------------- +Version 5.2.1, xxxx +^^^^^^^^^^^^^^^^^^^ + +- Updated regression tests to avoid blocking web server. + (https://github.com/lbl-srg/BuildingsPy/issues/605) + Version 5.2.0, March 14, 2025 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index e4a3375a..447960f9 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -2222,8 +2222,8 @@ def _compareResults(self, data_idx, oldRefFulFilNam, y_sim, y_tra, refFilNam, an noOldResults.append(varNam) if len(errors) > 0: self._reporter.writeError( - "{}: Errors during result verification.\n {}".format( - refFilNam, '\n '.join(errors))) + "{} has errors during result verification.\n {}".format( + model_name, '\n '.join(errors))) # Compare the simulation statistics # There are these cases: # 1. The old reference results have no statistics, in which case new results may be written. @@ -2261,7 +2261,9 @@ def _compareResults(self, data_idx, oldRefFulFilNam, y_sim, y_tra, refFilNam, an print("(Close plot window to continue.)") self._legacy_plot(y_sim, t_ref, y_ref, noOldResults, timOfMaxErr, matFilNam) else: - self._funnel_plot(model_name) + idx = next(i for i, el in enumerate(self._comp_info) if el['model'] == model_name) + comp_data = self._comp_info[idx]['comparison'] + Tester._funnel_plot(comp_data, self._PLOT_TEMPLATE) while not (ans == "n" or ans == "y" or ans == "Y" or ans == "N"): ans = input(" Enter: y(yes), n(no), Y(yes for all), N(no for all): ") @@ -2272,11 +2274,10 @@ def _compareResults(self, data_idx, oldRefFulFilNam, y_sim, y_tra, refFilNam, an return (updateReferenceData, (newTrajectories or newStatistics), ans) - def _funnel_plot(self, model_name, browser=None): + @staticmethod + def _funnel_plot(comp_data, plot_template): """Plot comparison results generated by pyfunnel.""" - idx = next(i for i, el in enumerate(self._comp_info) if el['model'] == model_name) - comp_data = self._comp_info[idx]['comparison'] dict_var_info = defaultdict(list) for iv, v in enumerate(comp_data['variables']): dict_var_info[v].append({'group': comp_data['var_groups'][iv], @@ -2300,7 +2301,7 @@ def _funnel_plot(self, model_name, browser=None): (1 + max(0, max(comp_data['var_groups']) - max_plot_per100) / max_plot_per100) err_plot_height = 0.18 * 100 / height # Populate the plot template. - with open(self._PLOT_TEMPLATE, 'r') as f: + with open(plot_template, 'r') as f: template = f.read() content = re.sub(r'\$PAGE_TITLE', plot_title, template) content = re.sub(r'\$TITLE', plot_title, content) @@ -2308,10 +2309,15 @@ def _funnel_plot(self, model_name, browser=None): content = re.sub(r'\$HEIGHT', '{}%'.format(height), content) content = re.sub(r'\$ERR_PLOT_HEIGHT', str(err_plot_height), content) # Launch the local server. + Tester._run_web_server(content, list_files) + + @staticmethod + def _run_web_server(content, list_files): + server = pyfunnel.MyHTTPServer(('', 0), pyfunnel.CORSRequestHandler, str_html=content, url_html='funnel') # Start the browser instance. - server.browse(list_files, browser=browser) + server.browse(list_files, timeout=0, browser=None) def _legacy_plot(self, y_sim, t_ref, y_ref, noOldResults, timOfMaxErr, model_name): """Plot comparison results generated by legacy comparison algorithm.""" diff --git a/requirements.txt b/requirements.txt index 1f3b570d..b62aec0d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ gitpython>=3.1.33; python_version>='3.8' pytidylib==0.3.2 simplejson==3.16.0 six==1.14.0 -pyfunnel==1.0.2 +pyfunnel==1.0.3 PyYAML==6.0.1 cerberus==1.3.4 diff --git a/setup.py b/setup.py index e27ba806..871d0d43 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ 'pytidylib>=0.3.2', 'simplejson>=3.16', 'six>=1.14', - 'pyfunnel>=1.0.2', + 'pyfunnel>=1.0.3', 'PyYAML>=6.0.1', 'cerberus>=1.3.4', ],