diff --git a/.travis.yml b/.travis.yml index 3ff5a637c..be609d71a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,9 @@ jobs: - python: 3.9 install: pip install --upgrade pip && pip install pandas==1.2.5 numpy==1.20.2 matplotlib==3.3.4 requests==2.25.1 script: cd testing && make build_jm_image && make test_kpis + - python: 3.9 + install: pip install --upgrade pip && pip install pandas==1.2.5 numpy==1.20.2 matplotlib==3.3.4 requests==2.25.1 + script: cd testing && make build_jm_image && make test_testcase - python: 3.9 install: pip install --upgrade pip && pip install pandas==1.2.5 numpy==1.20.2 matplotlib==3.3.4 requests==2.25.1 script: cd testing && make build_jm_image && make test_readme_commands diff --git a/releasenotes.md b/releasenotes.md index 94c98e27d..be6d7ffcd 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -13,6 +13,10 @@ Released on xx/xx/xxxx. - 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). +**The following changes are backwards-compatible, but might change benchmark results:** + +- Fix check on control input overwrite in ``testcase.TestCase.advance`` when overwriting a value of 0. This will change results if using BOPTEST-Service and delivering control input overwrites, with value of 0, in an /advance request using the ``json`` attribute with the python requests library. This is for [#533](https://github.com/ibpsa/project1-boptest/issues/533). + ## BOPTEST v0.4.0 diff --git a/testcase.py b/testcase.py index d486e8f61..f18d5d098 100644 --- a/testcase.py +++ b/testcase.py @@ -227,7 +227,7 @@ def advance(self, u): u : dict Defines the control input data to be used for the step. {_activate : bool, int, float, or str convertable to 1 or 0 - _u : int or float} + _u : int or float, or str convertable to float} Returns ------- @@ -276,7 +276,7 @@ def advance(self, u): message = "Unexpected input variable: {}.".format(key) logging.error(message) return status, message, payload - if key != 'time' and u[key]: + if (key != 'time' and (u[key] != None)): if '_activate' in key: try: if float(u[key]) == 1: diff --git a/testing/makefile b/testing/makefile index 12cf3629b..0b3fe89a3 100644 --- a/testing/makefile +++ b/testing/makefile @@ -36,6 +36,15 @@ copy_testcase_to_jm: docker cp ../version.txt ${IMG_NAME}:/usr/local/testing/${TESTCASE} make exec_jm ARGS="touch ${TESTCASE}/__init__.py" +copy_framework_with_testcase_to_jm: + make copy_to_jm ARGS=data + make copy_to_jm ARGS=kpis + make copy_to_jm ARGS=forecast + docker cp ../testcase.py ${IMG_NAME}:/usr/local/testing + docker cp ../version.txt ${IMG_NAME}:/usr/local/testing + docker exec -it ${IMG_NAME} /bin/bash -c "mkdir /usr/local/testing/testcases && exit" + docker cp ../testcases/${TESTCASE} ${IMG_NAME}:/usr/local/testing/testcases/${TESTCASE} + copy_from_jm: docker cp ${IMG_NAME}:/usr/local/testing/${ARGS} ../${ARGS} @@ -208,6 +217,20 @@ test_kpis: # Report test results python report.py +test_testcase: +# Run jm docker container + make run_jm +# Copy the required files and folders for the test + make copy_framework_with_testcase_to_jm TESTCASE=bestest_air +# Run test_kpis.py + make exec_jm ARGS="python test_testcase.py" + docker cp ${IMG_NAME}:/usr/local/testing/references/testcase ./references + docker cp ${IMG_NAME}:/usr/local/testing/test_testcase.log ./test_testcase.log +# Stop jm docker container + make stop_jm +# Report test results + python report.py + test_readme_commands: # Test readme commands work right after instantiation of test case container cd .. && TESTCASE=testcase2 docker-compose up -d @@ -250,6 +273,7 @@ test_all: make test_data make test_forecast make test_kpis + make test_testcase make test_readme_commands make test_testcase1 make test_testcase2 diff --git a/testing/references/testcase/check_input_for_zero.csv b/testing/references/testcase/check_input_for_zero.csv new file mode 100644 index 000000000..9c818c86c --- /dev/null +++ b/testing/references/testcase/check_input_for_zero.csv @@ -0,0 +1,6 @@ +time,fcu_oveFan_u,fcu_reaPFan_y +0.0,0.0,0.0 +30.0,0.5,21.3939783147 +60.0,0.5,21.6302109413 +90.0,0.0,6.50343645203e-05 +120.0,0.0,4.24847777137e-11 diff --git a/testing/test_testcase.py b/testing/test_testcase.py new file mode 100644 index 000000000..03c06d705 --- /dev/null +++ b/testing/test_testcase.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +""" +This module implements unit tests testcase.py. + +""" + +import os +import unittest +import pandas as pd +import testcase +import utilities + +reference_result_directory = 'testcase' + +class Advance(unittest.TestCase, utilities.partialChecks): + '''Unit tests for the testcase.TestCase.advance API. + + ''' + + def test_check_input_for_zero(self): + '''Test that an overwrite value of 0 given in float is used. + + ''' + + self.testcase.set_step(60) + # Advance first wih fan speed of 0.5, then with fan speed of 0.0. + u = {'fcu_oveFan_u': 0.5, + 'fcu_oveFan_activate':1} + status, message, payload = self.testcase.advance(u) + u = {'fcu_oveFan_u': 0.0, + 'fcu_oveFan_activate':1} + status, message, payload = self.testcase.advance(u) + # Get results + status, message, payload = self.testcase.get_results(['fcu_reaPFan_y', 'fcu_oveFan_u'], + 0, + payload['time']) + # Test results + df = pd.DataFrame(payload).set_index('time') + ref_filepath = os.path.join(utilities.get_root_path(), 'testing', 'references', reference_result_directory, 'check_input_for_zero.csv') + self.compare_ref_timeseries_df(df, ref_filepath) + + def setUp(self): + '''Set up for unit tests. Uses bestest_air. + + ''' + + self.testcase = testcase.TestCase(fmupath='testcases/bestest_air/models/wrapped.fmu') + +if __name__ == '__main__': + utilities.run_tests(os.path.basename(__file__)) diff --git a/testing/utilities.py b/testing/utilities.py index a09431528..28f08d051 100644 --- a/testing/utilities.py +++ b/testing/utilities.py @@ -155,7 +155,7 @@ def compare_ref_timeseries_df(self, df, ref_filepath): df : pandas DataFrame Test dataframe with "time" as index. ref_filepath : str - Reference file path relative to testing directory. + Reference file path. Returns -------