Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
235 changes: 235 additions & 0 deletions .github/workflows/docker_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
name: Docker Tests

on:
push:
branches: [ '*' ]
pull_request:
branches: [ main, master ]

jobs:
test-docker-workflow:
name: Test Docker Workflow Image
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 workflow image
run: |
docker build -f docker/Dockerfile.workflow -t constrain:test .

- name: Test default workflow execution
run: |
echo "Running default G36 demo workflow..."
docker run --rm constrain:test > docker_workflow_output.log 2>&1

# Check if workflow completed successfully
if grep -q "Workflow completed successfully!" docker_workflow_output.log; then
echo "[PASS] Docker workflow test PASSED - Workflow completed successfully"
cat docker_workflow_output.log
exit 0
else
echo "[FAIL] Docker workflow test FAILED - 'Workflow completed successfully!' not found in output"
echo "Docker output:"
cat docker_workflow_output.log
exit 1
fi

- name: Upload Docker workflow output log
if: always()
uses: actions/upload-artifact@v4
with:
name: docker-workflow-output
path: docker_workflow_output.log
retention-days: 7

test-docker-verification:
name: Test Docker Verification Image
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 verification image
run: |
docker build -f docker/Dockerfile.verification -t constrain-verification:test .

- name: Test help command
run: |
echo "Testing help command..."
docker run --rm constrain-verification:test --help > docker_verification_help.log 2>&1

# Check if help text is displayed
if grep -qi "usage:" docker_verification_help.log || grep -q "Run a single ConStrain verification case" docker_verification_help.log; then
echo "[PASS] Help command test PASSED"
cat docker_verification_help.log
else
echo "[FAIL] Help command test FAILED - Expected help text not found"
cat docker_verification_help.log
exit 1
fi

- name: Test verification execution with example data
run: |
echo "Running verification case with example data..."
docker run --rm \
-v ${{ github.workspace }}/docker/examples/verification_cases:/app/workflows \
-v ${{ github.workspace }}/docker/examples/data:/app/data \
-v ${{ github.workspace }}/docker/examples/schema:/app/schema \
constrain-verification:test \
/app/workflows/G36_library_verification_cases.json \
--data /app/data/G36_Modelica_Jan.csv \
--lib-items /app/schema/library.json > docker_verification_output.log 2>&1

# Check if verification completed successfully
if grep -q "Verification completed successfully!" docker_verification_output.log; then
echo "[PASS] Docker verification test PASSED - Verification completed successfully"
cat docker_verification_output.log
exit 0
else
echo "[FAIL] Docker verification test FAILED - 'Verification completed successfully!' not found in output"
echo "Docker output:"
cat docker_verification_output.log
exit 1
fi

- name: Upload Docker verification output log
if: always()
uses: actions/upload-artifact@v4
with:
name: docker-verification-output
path: docker_verification_output.log
retention-days: 7

- name: Upload Docker verification help log
if: always()
uses: actions/upload-artifact@v4
with:
name: docker-verification-help
path: docker_verification_help.log
retention-days: 7

test-docker-reporting:
name: Test Docker Reporting Image
runs-on: ubuntu-latest
needs: test-docker-verification # Run after verification to use its results

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

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

- name: Build Docker reporting image
run: |
docker build -f docker/Dockerfile.reporting -t constrain-reporting:test .

- name: Test help command
run: |
echo "Testing help command..."
docker run --rm constrain-reporting:test --help > docker_reporting_help.log 2>&1

# Check if help text is displayed
if grep -qi "usage:" docker_reporting_help.log || grep -q "Generate summary reports from verification case results" docker_reporting_help.log; then
echo "[PASS] Help command test PASSED"
cat docker_reporting_help.log
else
echo "[FAIL] Help command test FAILED - Expected help text not found"
cat docker_reporting_help.log
exit 1
fi

- name: Build verification image for test data
run: |
docker build -f docker/Dockerfile.verification -t constrain-verification:test .

- name: Generate test verification results
run: |
echo "Generating verification results for reporting test..."
mkdir -p ${{ github.workspace }}/docker/examples_results_test
docker run --rm \
-v ${{ github.workspace }}/docker/examples/verification_cases:/app/workflows \
-v ${{ github.workspace }}/docker/examples/data:/app/data \
-v ${{ github.workspace }}/docker/examples/schema:/app/schema \
-v ${{ github.workspace }}/docker/examples_results_test:/app/results \
constrain-verification:test \
/app/workflows/G36_library_verification_cases.json \
--data /app/data/G36_Modelica_Jan.csv \
--lib-items /app/schema/library.json \
--output /app/results > docker_verification_setup.log 2>&1 || true

echo "Verification results generated (or using existing results)"

- name: Test reporting execution
run: |
echo "Running reporting with verification results..."
docker run --rm \
-v ${{ github.workspace }}/docker/examples_results_test:/app/results \
constrain-reporting:test \
"/app/results/*_md.json" \
--output test_summary.md > docker_reporting_output.log 2>&1

# Check if reporting completed successfully
if grep -q "Report generated successfully!" docker_reporting_output.log; then
echo "[PASS] Docker reporting test PASSED - Report generated successfully"
cat docker_reporting_output.log
exit 0
else
echo "[FAIL] Docker reporting test FAILED - 'Report generated successfully!' not found in output"
echo "Docker output:"
cat docker_reporting_output.log
exit 1
fi

- name: Test log-level option
run: |
echo "Testing --log-level option..."
docker run --rm \
-v ${{ github.workspace }}/docker/examples_results_test:/app/results \
constrain-reporting:test \
"/app/results/*_md.json" \
--output test_summary.md \
--log-level DEBUG > docker_reporting_loglevel.log 2>&1 || true

# Check that --log-level is accepted (no "unrecognized arguments" error)
if grep -q "unrecognized arguments.*--log-level" docker_reporting_loglevel.log; then
echo "[FAIL] Log level test FAILED - --log-level not recognized"
cat docker_reporting_loglevel.log
exit 1
else
echo "[PASS] Log level test PASSED - --log-level option accepted"
cat docker_reporting_loglevel.log
fi

- name: Upload Docker reporting output log
if: always()
uses: actions/upload-artifact@v4
with:
name: docker-reporting-output
path: docker_reporting_output.log
retention-days: 7

- name: Upload Docker reporting help log
if: always()
uses: actions/upload-artifact@v4
with:
name: docker-reporting-help
path: docker_reporting_help.log
retention-days: 7

- name: Upload Docker reporting log-level test log
if: always()
uses: actions/upload-artifact@v4
with:
name: docker-reporting-loglevel
path: docker_reporting_loglevel.log
retention-days: 7
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ docs/_modules
docs/_sources
docs/_static
docs/.doctrees
**.DS_Store
**.DS_Store
dev/
*.png
constrain/demo/api_demo/*.json
/*.json
/*.md
results
tests/api/data/verification_output/*.md
tests/outputs/*.csv
poetry.lock
1 change: 1 addition & 0 deletions constrain/api/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
self.result_md_path = f"{self.result_md_dir}/{self.result_md_name}"
self.md_dict_dump = {}
self.verification_item_case_id_mapping = {}
self.caseids_sorted = []

# TODO: refactor below to make mapping creation more efficient
for json_file in glob.glob(self.verification_json):
Expand Down
7 changes: 5 additions & 2 deletions constrain/api/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ def configure(
logging.error("An output_path argument should be specified.")
return None
elif not os.path.isdir(output_path):
logging.error("The specified output directory does not exist.")
return None
# Create the output directory if it doesn't exist
logging.warning(
f"Output directory {output_path} does not exist. Creating it."
)
os.makedirs(output_path, exist_ok=True)

if time_series_csv_export_name_prefix is not None:
if not isinstance(time_series_csv_export_name_prefix, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"position_damper_air_outdoor_min": "min_oa_p",
"position_damper_air_outdoor_max": "max_oa_p",
"flag_economizer_limit": "economizer_high_limit_reached"
}
},
"parameters": {}
},
"verification_class": "G36OutdoorAirDamperPositionForReliefDamperOrFan"
},
Expand Down
11 changes: 6 additions & 5 deletions constrain/libcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def run_libcase(
if need_injection or run_sim:
original_idf_path = item.item["simulation_IO"]["idf"].strip()

instrumented_idf_path = None
if need_injection:
idd_path = item.item["simulation_IO"]["idd"].strip()
if ".idf" in original_idf_path.lower():
Expand Down Expand Up @@ -96,11 +97,11 @@ def run_libcase(
year=2000,
).transform()
else:
df = DateTimeEP(
item.read_points_values(
csv_path=f"{instrumented_idf_path.replace('.idf', '')}/{item.item['simulation_IO']['output']}"
)
).transform()
if instrumented_idf_path is None:
csv_path = f"{item.item['simulation_IO']['output']}"
else:
csv_path = f"{instrumented_idf_path.replace('.idf', '')}/{item.item['simulation_IO']['output']}"
df = DateTimeEP(item.read_points_values(csv_path=csv_path)).transform()
verification_class = item.item["verification_class"]

parameters = (
Expand Down
Loading
Loading