diff --git a/.github/actions/unit-test-action/action.yml b/.github/actions/unit-test-action/action.yml new file mode 100644 index 0000000..54867b9 --- /dev/null +++ b/.github/actions/unit-test-action/action.yml @@ -0,0 +1,4 @@ +name: 'Unit Test Action' +runs: + using: 'docker' + image: '../../../Dockerfile' \ No newline at end of file diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 0000000..2695464 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,45 @@ +on: + push: + branches: [ '*' ] + +jobs: + run-python-unit-tests: + name: Run python unit tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and run unit test Dockerfile + uses: ./.github/actions/unit-test-action + + - name: Upload Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: test_results + path: ${{ github.workspace }}/test_results + + - name: Check test results + run: | + cat test_results/test_output.txt + if [ -f test_results/test_failed.txt ]; then + echo "Some tests failed. Check the test output files for details." + else + echo "All tests passed successfully." + fi + + - name: Update measure.xmls + run: | + cat test_results/measure_check_output.txt + git config user.name "GitHub Actions Bot" + git config user.email "actions@github.com" + git add **/measure.xml + if git diff --cached --quiet; then + echo "No changes to measure.xml files. Skipping commit." + else + git commit -m "Auto-update measure.xml files by GitHub Actions" + git push origin HEAD + fi \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3dec25a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.12 + +RUN wget https://github.com/NREL/OpenStudio/releases/download/v3.9.0/OpenStudio-3.9.0+c77fbb9569-Ubuntu-22.04-x86_64.tar.gz && \ + tar -xvzf OpenStudio-3.9.0+c77fbb9569-Ubuntu-22.04-x86_64.tar.gz && \ + cp -r OpenStudio-3.9.0+c77fbb9569-Ubuntu-22.04-x86_64/usr/local/openstudio-3.9.0 /usr/local/openstudio && \ + rm -rf OpenStudio-3.9.0+c77fbb9569-Ubuntu-22.04-x86_64.tar.gz + +ENV PATH="/usr/local/openstudio/bin:${PATH}" + +# Set the working directory within the container +WORKDIR /app + +# Copy the current directory contents into the container +COPY . /app + +# Install Python dependencies +RUN pip install --no-cache-dir -r ./requirements.txt + +# Find directories containing measure.py and run tests' +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..8f5512e --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +mkdir $GITHUB_WORKSPACE/test_results + +python_exec=$(which python3) +python_version=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") +python_lib=$(dirname $(dirname $python_exec))/lib/python$python_version +python_site_packages=$(python3 -c "import site; print(site.getsitepackages()[0])") + +echo $python_exec +echo $python_lib +echo $python_site_packages + +openstudio measure -t ./lib/measures >> $GITHUB_WORKSPACE/test_results/measure_check_output.txt + + +for dir in $(find . -type f \( -name 'measure.rb' -o -name 'measure.py' \) -exec dirname {} \;); do + openstudio --python_path "$python_lib" --python_path "$python_site_packages" measure --run_tests $dir >> $GITHUB_WORKSPACE/test_results/test_output.txt + if [ $? -ne 0 ]; then + echo $dir >> $GITHUB_WORKSPACE/test_results/test_failed.txt + fi +done + +if [ -f $GITHUB_WORKSPACE/test_results/test_failed.txt ]; then + echo "Some tests failed. Check the test output files for details." +else + echo "All tests passed successfully." +fi \ No newline at end of file diff --git a/lib/measures/ConstrainSupplyAirTemperatureResetVerification/measure.xml b/lib/measures/ConstrainSupplyAirTemperatureResetVerification/measure.xml index e37324a..6923883 100644 --- a/lib/measures/ConstrainSupplyAirTemperatureResetVerification/measure.xml +++ b/lib/measures/ConstrainSupplyAirTemperatureResetVerification/measure.xml @@ -3,8 +3,8 @@ 3.1 constrain_supply_air_temperature_reset_verification 7f59756b-16e7-4bb2-a122-7e7a3a8bfbc6 - 54f5d1b9-a933-4ecb-96c6-11f954165f26 - 2024-09-30T22:52:39Z + 9c979c9d-a00f-4774-9b99-6b0b6de18514 + 2024-12-20T20:55:20Z 6A20E99B ConstrainSupplyAirTemperatureResetVerification Supply Air Temperature Reset Verification @@ -67,7 +67,7 @@ LICENSE.md md license - 00000000 + 67DFE812 README.md @@ -84,7 +84,7 @@ measure.py py script - 6CDC5A23 + F5C61748 __init__.py @@ -108,7 +108,7 @@ test_measure.py py test - E483C774 + 820C8890 diff --git a/lib/measures/CreateTypicalBuilding/measure.xml b/lib/measures/CreateTypicalBuilding/measure.xml index 08fc491..d9c7a90 100644 --- a/lib/measures/CreateTypicalBuilding/measure.xml +++ b/lib/measures/CreateTypicalBuilding/measure.xml @@ -3,8 +3,8 @@ 3.1 create_typical_building fa93dfc5-9f4f-4f8f-9db7-3aa5ccf38e5d - 57ae1469-01ed-4d84-9d70-86ae11df35e0 - 2024-06-27T21:00:44Z + 4ce62f50-b7d1-46a3-b2e2-c8e89c99199f + 2024-12-20T20:55:22Z 6CE0A70A CreateTypicalBuilding Create Typical Building @@ -221,6 +221,10 @@ Existing HVAC Existing HVAC + + Inferred + Inferred + JSON specified JSON specified @@ -902,25 +906,13 @@ LICENSE.md md license - 7C2CADD0 + EAF3EFF6 README.md md readme - 5208BBA1 - - - README.md.erb - erb - readmeerb - F1C26127 - - - .gitkeep - gitkeep - doc - 00000000 + 28346E7B @@ -931,13 +923,13 @@ measure.rb rb script - A52F4719 + FC46D139 create_typical_resources.rb rb resource - 1E789C5E + 3CBA4D47 create_typical_building_test.rb @@ -955,7 +947,7 @@ source/ASHRAESmallOffice.osm osm test - ECC84F01 + 5ECE7EF1 source/hvac_mapping_path/hvac_zone_mapping.json diff --git a/lib/measures/GenerateConStrainReport/measure.xml b/lib/measures/GenerateConStrainReport/measure.xml index 14634b5..26ce909 100644 --- a/lib/measures/GenerateConStrainReport/measure.xml +++ b/lib/measures/GenerateConStrainReport/measure.xml @@ -1,11 +1,11 @@ 3.1 - Failed to infer measure name from '/mnt/c/OSSTD_repos/openstudio-building-energy-standard-measures-gem/./lib/measures/GenerateConStrainReport/measure.py' + Failed to infer measure name from '/github/workspace/./lib/measures/GenerateConStrainReport/measure.py' generate_constrain_report 5cd98b4e-ddfe-44ab-9dca-d9885f57a316 - 379648d5-0c18-45b2-9fed-3df585a419d8 - 2024-08-29T17:41:59Z + 3c70256e-4c79-4172-9daf-a7b4ad06e761 + 2024-12-20T20:55:20Z 7C9D3672 GenerateConStrainReport Generate a ConStrain report. @@ -48,7 +48,7 @@ LICENSE.md md license - 00000000 + 1A54BA1E README.md @@ -101,7 +101,7 @@ test_measure.py py test - EA55421A + 609009C1 diff --git a/lib/measures/GenerateConStrainReport/tests/test_measure.py b/lib/measures/GenerateConStrainReport/tests/test_measure.py index 53f62e1..60e21c0 100644 --- a/lib/measures/GenerateConStrainReport/tests/test_measure.py +++ b/lib/measures/GenerateConStrainReport/tests/test_measure.py @@ -1,7 +1,7 @@ import pytest import openstudio import pathlib -from ..measure import GenerateConStrainReport +from measure import GenerateConStrainReport import logging @@ -31,8 +31,8 @@ def test_good_argument_values(self): argument_map = openstudio.measure.convertOSArgumentVectorToMap(arguments) args_dict = {} - args_dict["workflow_path"] = ( - "tests/test_files/G36_demo_workflow.json" + args_dict["workflow_path"] = str( + pathlib.Path(__file__).parent.absolute() / "test_files" / "G36_demo_workflow.json" ) for arg in arguments: diff --git a/lib/measures/GenerateIPLVChillerElectricEIRPerformanceCurves/measure.xml b/lib/measures/GenerateIPLVChillerElectricEIRPerformanceCurves/measure.xml index 8be6880..3339730 100644 --- a/lib/measures/GenerateIPLVChillerElectricEIRPerformanceCurves/measure.xml +++ b/lib/measures/GenerateIPLVChillerElectricEIRPerformanceCurves/measure.xml @@ -1,10 +1,11 @@ 3.1 + Failed to infer measure name from '/github/workspace/./lib/measures/GenerateIPLVChillerElectricEIRPerformanceCurves/measure.py' generate_iplv_specific_chiller_performance_curves_for_chillers 5cd98b4e-ddfe-44ab-9dca-d9885f57a216 - 9eeccbb6-7517-4337-9feb-fcee913c7cf8 - 2024-04-24T19:59:05Z + df9990dc-cc82-4e71-92e6-f847c4eb1000 + 2025-02-05T19:19:27Z 905C4D50 GenerateIPLVChillerElectricEIRPerformanceCurves Generate IPLV-specific Chiller Performance Curves for Chillers (Chiller:Electric:EIR). diff --git a/lib/measures/PerformanceRatingMethod/measure.xml b/lib/measures/PerformanceRatingMethod/measure.xml index d1e7827..f19dba1 100644 --- a/lib/measures/PerformanceRatingMethod/measure.xml +++ b/lib/measures/PerformanceRatingMethod/measure.xml @@ -3,8 +3,8 @@ 3.1 create_baseline_building a984a630-2a41-45fd-80ec-6454777bf253 - 6d81dd33-9c51-47f5-a1e3-c0fcfac0322f - 2024-04-30T17:17:19Z + ebff5243-0083-4a3f-bd50-5fa787437d8e + 2024-12-20T20:55:20Z 8FF2A4FA CreateBaselineBuilding Create ASHRAE 90.1-2019 PRM Model @@ -614,7 +614,7 @@ measure.rb rb script - 0E314AA6 + C7F8661D ASHRAE9012019PRM_Test.rb diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0b54e0c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Constrain==0.6.0 +copper-bem==0.2.3 \ No newline at end of file