git clone https://github.com/andreaemmanuele/haos_smartgate.git
cd haos_smartgatepip install -r requirements.txt
pip install -r requirements-test.txt./setup-hooks.shThis configures pre-commit hooks to run tests automatically before each commit.
This project uses Black for Python formatting. All code must be formatted before committing.
black .black app/main.pyblack --check .Install the Black Formatter extension, then add to .vscode/settings.json:
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}The pre-commit hook runs black --check . automatically — commits will be rejected if any file is not formatted.
Execute the complete test suite:
pytest -vTest a single module:
# OCR comparison tests (old vs AI SR)
pytest app/tests/test_enhancement_ocr_comparison.py -v
# Image processing tests
pytest app/tests/test_image_processing.py -v
# OCR pattern extraction tests
pytest app/tests/test_ocr.py -vExecute a specific test with detailed output:
pytest app/tests/test_enhancement_ocr_comparison.py::test_ocr_comparison -v -sFlags:
-v(verbose): Show detailed test names-s: Show print statements and logging output
Generate coverage report:
# Terminal output
pytest --cov=. --cov-report=term-missing
# HTML report
pytest --cov=. --cov-report=html
# Open htmlcov/index.html in browserExecute tests by name pattern:
# Run all OCR-related tests
pytest -k "ocr" -v
# Run all comparison tests
pytest -k "comparison" -v# Fast: skip slow tests
pytest -v -m "not slow"
# Debug: stop on first failure
pytest -x
# Watch mode: re-run on file changes (requires pytest-watch)
ptw -- -vFor OCR comparison tests, add real plate images:
# Copy from Home Assistant
scp root@HA_IP:/config/www/smart_gate/snapshot/debug/last_plate_crop.jpg \
app/tests/fixtures/plates/sample_plate_GR571XC.png
# Run comparison
pytest app/tests/test_enhancement_ocr_comparison.py::test_ocr_comparison_summary -v -sExpected output:
======================================================================
Image: sample_plate_GR571XC.png
======================================================================
Expected plate: GR571XC
Old algorithm: 'CR571XC' (confidence: 0.810)
New AI SR: 'GR571XC' (confidence: 0.967)
Old match: ❌
New match: ✅ IMPROVED
The pre-commit hook runs black --check . and the full test suite before allowing a commit.
To skip (not recommended):
git commit --no-verify