Skip to content

Commit

Permalink
Merge pull request #544 from ibpsa/issue533_cheKey
Browse files Browse the repository at this point in the history
Closes #533
  • Loading branch information
dhblum authored Aug 24, 2023
2 parents 1fd9663 + a76c6af commit db0f10e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def advance(self, u):
u : dict
Defines the control input data to be used for the step.
{<input_name>_activate : bool, int, float, or str convertable to 1 or 0
<input_name>_u : int or float}
<input_name>_u : int or float, or str convertable to float}
Returns
-------
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions testing/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions testing/references/testcase/check_input_for_zero.csv
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions testing/test_testcase.py
Original file line number Diff line number Diff line change
@@ -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__))
2 changes: 1 addition & 1 deletion testing/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down

0 comments on commit db0f10e

Please sign in to comment.