Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Measure Unit Test Action #19

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9e7aee7
Add python unit tests job
jslane-h Oct 23, 2024
d224b15
Fix deprecated command
jslane-h Oct 23, 2024
d92b6b0
Update python_measure_dirs format
jslane-h Oct 23, 2024
07fa9d3
Add copper dependency
jslane-h Oct 23, 2024
e26c295
Fix measure import
jslane-h Oct 23, 2024
93b3843
Add constrain import
jslane-h Oct 23, 2024
e8acb50
Update test_file path
jslane-h Oct 23, 2024
3fd135c
Remove pythonpath var
jslane-h Oct 24, 2024
b92ceb9
WIP: Add measure check
jslane-h Nov 25, 2024
9e59393
Install openstudio cli in action
jslane-h Nov 25, 2024
12b0819
Test to see if able to build container with openstudio
jslane-h Nov 27, 2024
ffcaf53
Update dockerfile
jslane-h Nov 27, 2024
41e3934
Fix dockerfile
jslane-h Nov 27, 2024
dfe1e65
Update build docker image step
jslane-h Nov 27, 2024
342487b
Update action
jslane-h Nov 27, 2024
3bb2fd3
Update action
jslane-h Nov 27, 2024
d53eca0
Test action
jslane-h Nov 27, 2024
ee83fc4
Update action
jslane-h Nov 27, 2024
c5e0cad
Debug action
jslane-h Nov 27, 2024
cc58c0a
Test action
jslane-h Nov 27, 2024
30bc55b
Test storing test results in github workspace due to file permissions
jslane-h Dec 2, 2024
d11abaa
Use github workspace as working directory
jslane-h Dec 2, 2024
e21faab
Change github workspace var
jslane-h Dec 4, 2024
3e03ddb
Update github workspace var
jslane-h Dec 4, 2024
4fe2f52
try checkout v4
jslane-h Dec 4, 2024
6ea224d
move Dockerfile to actions folder
jslane-h Dec 4, 2024
7bec849
debug
jslane-h Dec 4, 2024
5ec527f
debug
jslane-h Dec 4, 2024
8dffb8d
Create action yaml
jslane-h Dec 4, 2024
8e0cd62
test
jslane-h Dec 4, 2024
9e4f096
Use $GITHUB_WORKSPACE in container
jslane-h Dec 4, 2024
9bab626
Add entrypoint file
jslane-h Dec 4, 2024
52678b0
Fix entrypoint
jslane-h Dec 4, 2024
ab27c8a
Fix entrypoint script
jslane-h Dec 4, 2024
b9cd8bb
Output to test_results folder (it is finally working)
jslane-h Dec 4, 2024
6380b54
Test update measure xml's
jslane-h Dec 20, 2024
2ab05ea
Auto-update measure.xml files by GitHub Actions
actions-user Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
push:
branches: [ '*' ]

jobs:
run-python-unit-tests:
name: Run python unit tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
run: |
docker build -t python_measure_test .
docker run --rm \
-v ${{ github.workspace }}/test_results:/app/test_results \
python_measure_test

- name: Check for FAILURE in pytest_output.txt
run: |
ls test_results
# cat test_results/pytest_output.txt
# if grep -q 'FAILURE' test_results/pytest_output.txt; then
# exit 1
# fi

- name: Upload Test Results
uses: actions/upload-artifact@v3
with:
name: test_results
path: test_results/
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Start with the OpenStudio image
FROM python:3.10

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
Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weilixu - should we always test using the latest version of OpenStudio?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure - I guess it should depends on the measure dependency. If all measures move at the same pace, we can use the latest OS version for testing.


ENV PATH="/usr/local/openstudio/bin:${PATH}"

# Set Python 3 as the default Python
RUN ln -s /usr/bin/python3 /usr/bin/python

# Install Python dependencies
RUN pip install --no-cache-dir pytest openstudio copper-bem constrain

# Set the working directory within the container
WORKDIR /app

# Copy the current directory contents into the container
COPY . /app

# Find directories containing measure.py and run tests
RUN bash -c "\
mkdir test_results && \
openstudio measure -t ./lib/measures > test_results/measure_check_output.txt && \
for dir in \$(find . -type f -name 'measure.py' -exec dirname {} \; | sort -u); do \
pytest \$dir >> test_results/pytest_output.txt; \
done"
6 changes: 3 additions & 3 deletions lib/measures/GenerateConStrainReport/tests/test_measure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import openstudio
import pathlib
from ..measure import GenerateConStrainReport
from measure import GenerateConStrainReport
import logging


Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# Find directories containing measure.py
dirs = set(os.path.dirname(root) for root, _, files in os.walk('.') if 'measure.py' in files)

# Write directories to a file and run tests
with open('/app/python_measure_dirs.txt', 'w') as f:
for dir in dirs:
f.write(dir + '\n')
os.system(f'openstudio measure -t {dir} > {dir}/measure_check_output.txt')
os.system(f'pytest {dir} > {dir}/pytest_output.txt')
Loading