From 56d69774b58f531fb8437234ce189420ba09a61c Mon Sep 17 00:00:00 2001 From: David Blum Date: Fri, 25 Aug 2023 14:27:21 -0700 Subject: [PATCH 1/5] Add test to check for error condition --- testing/test_bestest_air.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/testing/test_bestest_air.py b/testing/test_bestest_air.py index 03f7a05db..34d36adac 100644 --- a/testing/test_bestest_air.py +++ b/testing/test_bestest_air.py @@ -8,6 +8,7 @@ import unittest import os import utilities +import requests class Run(unittest.TestCase, utilities.partialTestTimePeriod): '''Tests the example test case. @@ -43,6 +44,32 @@ def test_typical_cool_day(self): def test_mix_day(self): self.run_time_period('mix_day') + def test_scenario_flag(self): + '''Ensures the scenario flag is set properly. + + Parameters + ---------- + None + + Returns + ------- + None + + ''' + + length = 86400*14 + # Initialize test case scenario + requests.put('{0}/scenario'.format(self.url), json={'time_period':'peak_heat_day'}) + # Set simulation step + requests.put('{0}/step'.format(self.url), json={'step':length}).json()['payload'] + # Simulation Loop + requests.post('{0}/advance'.format(self.url)).json()['payload'] + # Try submit results to dashboard + status = requests.post("{0}/submit".format(self.url), json={"api_key": 'valid_key', + "unit_test":"True"}).json()['status'] + # Check result + self.assertEqual(status,200) + class API(unittest.TestCase, utilities.partialTestAPI): '''Tests the api for testcase. From d81b79e5833f2011a78f5cf6fda096ab0c35a69e Mon Sep 17 00:00:00 2001 From: David Blum Date: Fri, 25 Aug 2023 14:27:34 -0700 Subject: [PATCH 2/5] Make fix --- testcase.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testcase.py b/testcase.py index f18d5d098..cd24d49fe 100644 --- a/testcase.py +++ b/testcase.py @@ -344,6 +344,9 @@ def advance(self, u): message = alert_message # Advance start time self.start_time = self.final_time + # Check if scenario is over + if self.start_time >= self.end_time: + self.scenario_end = True # Log and return logging.info(message) return status, message, payload @@ -357,7 +360,6 @@ def advance(self, u): return status, message, payload else: # Simulation at end time - self.scenario_end = True payload = dict() message = "End of test case scenario time period reached." logging.info(message) From 139c222bc8d6f5714b2a3d8f912edad2c1aeb1fc Mon Sep 17 00:00:00 2001 From: David Blum Date: Fri, 25 Aug 2023 14:29:51 -0700 Subject: [PATCH 3/5] Update release notes --- releasenotes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/releasenotes.md b/releasenotes.md index be6d7ffcd..e4e27c157 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -12,6 +12,7 @@ Released on xx/xx/xxxx. - In unit test checking fetching of single forecast variable, specify specific forecast point to check for each test case. This is for [#529](https://github.com/ibpsa/project1-boptest/issues/529). - Update ``KPI_Calculator.get_computational_time_ratio`` to return ``None`` if no simulation steps have been processed. This is for [#540](https://github.com/ibpsa/project1-boptest/issues/540). - Add ``forecastParameters`` to dashboard submission with empty dictionary and update url for submitting dashboard results. This is for [#548](https://github.com/ibpsa/project1-boptest/issues/548). +- Fix so that results can be submitted to dashboard if sitting at end of scenario time period instead of needing to try to advance one step past. This is for [#546](https://github.com/ibpsa/project1-boptest/issues/546). **The following changes are backwards-compatible, but might change benchmark results:** From 836a30939a5b3ffa1916a940543a88fd5fd20d1c Mon Sep 17 00:00:00 2001 From: David Blum Date: Fri, 25 Aug 2023 14:49:04 -0700 Subject: [PATCH 4/5] Fix to reset step in test --- testing/test_bestest_air.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testing/test_bestest_air.py b/testing/test_bestest_air.py index 34d36adac..0597c1b5e 100644 --- a/testing/test_bestest_air.py +++ b/testing/test_bestest_air.py @@ -58,6 +58,8 @@ def test_scenario_flag(self): ''' length = 86400*14 + # Get current step + step_current = requests.get('{0}/step'.format(self.url)).json()['payload'] # Initialize test case scenario requests.put('{0}/scenario'.format(self.url), json={'time_period':'peak_heat_day'}) # Set simulation step @@ -69,6 +71,8 @@ def test_scenario_flag(self): "unit_test":"True"}).json()['status'] # Check result self.assertEqual(status,200) + # Return scenario and step to original + requests.put('{0}/step'.format(self.url), json={'step':step_current}) class API(unittest.TestCase, utilities.partialTestAPI): '''Tests the api for testcase. From fa5bfedb137bbe73cb0266814c121b2d0fb0b007 Mon Sep 17 00:00:00 2001 From: David Blum Date: Mon, 28 Aug 2023 06:22:59 -0700 Subject: [PATCH 5/5] Remove getting payload --- testing/test_bestest_air.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_bestest_air.py b/testing/test_bestest_air.py index 0597c1b5e..03437f208 100644 --- a/testing/test_bestest_air.py +++ b/testing/test_bestest_air.py @@ -63,9 +63,9 @@ def test_scenario_flag(self): # Initialize test case scenario requests.put('{0}/scenario'.format(self.url), json={'time_period':'peak_heat_day'}) # Set simulation step - requests.put('{0}/step'.format(self.url), json={'step':length}).json()['payload'] + requests.put('{0}/step'.format(self.url), json={'step':length}) # Simulation Loop - requests.post('{0}/advance'.format(self.url)).json()['payload'] + requests.post('{0}/advance'.format(self.url)) # Try submit results to dashboard status = requests.post("{0}/submit".format(self.url), json={"api_key": 'valid_key', "unit_test":"True"}).json()['status']