hass.tibber_prices/scripts/hassfest
Julian Pawlowski f60b5990ae test: add pytest framework and midnight-crossing tests
Set up pytest with Home Assistant support and created 6 tests for
midnight-crossing period logic (5 unit tests + 1 integration test).

Added pytest configuration, test dependencies, test runner script
(./scripts/test), and comprehensive tests for group_periods_by_day()
and midnight turnover consistency.

All tests pass in 0.12s.

Impact: Provides regression testing for midnight-crossing period bugs.
Tests validate periods remain visible across midnight turnover.
2025-11-21 23:47:01 +00:00

106 lines
3.5 KiB
Bash
Executable file

#!/bin/sh
# script/hassfest: Lightweight local validation for Home Assistant integration
# Note: This is a simplified version. Full hassfest runs in GitHub Actions.
set -e
cd "$(dirname "$0")/.."
INTEGRATION_PATH="custom_components/tibber_prices"
ERRORS=0
echo "==> Running local integration validation..."
echo ""
# Check 1: config_flow.py exists
echo "✓ Checking config_flow.py existence..."
if [ ! -f "$INTEGRATION_PATH/config_flow.py" ]; then
echo " ✗ ERROR: config_flow.py not found"
ERRORS=$((ERRORS + 1))
else
echo " ✓ config_flow.py exists"
fi
# Check 2: manifest.json syntax
echo "✓ Checking manifest.json syntax..."
if ! python -m json.tool "$INTEGRATION_PATH/manifest.json" > /dev/null 2>&1; then
echo " ✗ ERROR: manifest.json has invalid JSON syntax"
ERRORS=$((ERRORS + 1))
else
echo " ✓ manifest.json is valid JSON"
fi
# Check 3: Translation files syntax
echo "✓ Checking translation files syntax..."
for lang_file in "$INTEGRATION_PATH"/translations/*.json; do
if [ -f "$lang_file" ]; then
lang=$(basename "$lang_file")
if ! python -m json.tool "$lang_file" > /dev/null 2>&1; then
echo " ✗ ERROR: $lang has invalid JSON syntax"
ERRORS=$((ERRORS + 1))
else
echo "$lang is valid JSON"
fi
fi
done
# Check 4: Custom translation files syntax
if [ -d "$INTEGRATION_PATH/custom_translations" ]; then
echo "✓ Checking custom translation files syntax..."
for lang_file in "$INTEGRATION_PATH"/custom_translations/*.json; do
if [ -f "$lang_file" ]; then
lang=$(basename "$lang_file")
if ! python -m json.tool "$lang_file" > /dev/null 2>&1; then
echo " ✗ ERROR: custom_translations/$lang has invalid JSON syntax"
ERRORS=$((ERRORS + 1))
else
echo " ✓ custom_translations/$lang is valid JSON"
fi
fi
done
fi
# Check 5: Python syntax
# Note: We use ast.parse() instead of py_compile to avoid creating __pycache__ artifacts
# ast.parse() validates syntax without writing any files to disk
echo "✓ Checking Python syntax..."
PYTHON_ERRORS=0
find "$INTEGRATION_PATH" -name "*.py" -type f | while IFS= read -r py_file; do
if ! python -c "import ast; ast.parse(open('$py_file').read())" 2>/dev/null; then
echo " ✗ ERROR: $py_file has syntax errors"
PYTHON_ERRORS=$((PYTHON_ERRORS + 1))
ERRORS=$((ERRORS + 1))
fi
done
if [ $PYTHON_ERRORS -eq 0 ]; then
echo " ✓ All Python files have valid syntax"
fi
# Check 6: Required manifest fields
echo "✓ Checking required manifest fields..."
REQUIRED_FIELDS="domain name version documentation issue_tracker codeowners"
for field in $REQUIRED_FIELDS; do
if ! python -c "import json; data=json.load(open('$INTEGRATION_PATH/manifest.json')); exit(0 if '$field' in data else 1)" 2>/dev/null; then
echo " ✗ ERROR: manifest.json missing required field: $field"
ERRORS=$((ERRORS + 1))
fi
done
if [ $ERRORS -eq 0 ]; then
echo " ✓ All required manifest fields present"
fi
echo ""
if [ $ERRORS -eq 0 ]; then
echo "==> ✓ All local validation checks passed!"
echo ""
echo "Note: Full hassfest validation runs in GitHub Actions."
echo " Push your changes to run complete validation."
exit 0
else
echo "==> ✗ Found $ERRORS error(s)"
echo ""
echo "Note: This is a simplified local validation."
echo " Full hassfest validation runs in GitHub Actions."
exit 1
fi