mirror of
https://github.com/ElVit/esphome_components.git
synced 2026-10-21 01:57:10 +02:00
Merge pull request #34 from ElVit/desk/unit-tests
Added Unit Tests for Maidesite Desk
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
name: Test Maidesite Desk Component
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: read
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- 'desk**'
|
||||
paths:
|
||||
- 'components/maidesite_desk/**'
|
||||
- 'tests/maidesite_desk/**'
|
||||
- '.github/workflows/test_maidesite_desk.yml'
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'components/maidesite_desk/**'
|
||||
- 'tests/maidesite_desk/**'
|
||||
- '.github/workflows/test_maidesite_desk.yml'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test-build:
|
||||
name: Test ESPHome Build
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
board: [esp32s2, esp32c3, full]
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build ESPHome firmware for ${{ matrix.board }}
|
||||
uses: esphome/build-action@v7
|
||||
with:
|
||||
yaml-file: tests/maidesite_desk/test_maidesite_desk_${{ matrix.board == 'full' && 'full' || matrix.board }}.yaml
|
||||
version: latest
|
||||
|
||||
lint-code:
|
||||
name: Lint C++ Code
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install clang-format
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y clang-format
|
||||
|
||||
- name: Run clang-format check
|
||||
run: |
|
||||
find components/maidesite_desk -name '*.cpp' -o -name '*.h' | \
|
||||
xargs clang-format -style=file --dry-run --Werror
|
||||
|
||||
lint-python:
|
||||
name: Lint Python Code
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install linting tools
|
||||
run: |
|
||||
pip install --upgrade pip
|
||||
pip install flake8 pylint black
|
||||
|
||||
- name: Run black check
|
||||
run: |
|
||||
black --check components/maidesite_desk/
|
||||
|
||||
- name: Run flake8
|
||||
run: |
|
||||
flake8 components/maidesite_desk/ --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
flake8 components/maidesite_desk/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
|
||||
test-python:
|
||||
name: Python Unit Tests
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install --upgrade pip
|
||||
pip install pytest pytest-cov esphome
|
||||
|
||||
- name: Run Python unit tests
|
||||
run: |
|
||||
pytest tests/maidesite_desk/ -v --cov=components/maidesite_desk --cov-report=xml --cov-report=term
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
flags: unittests
|
||||
name: codecov-maidesite-desk
|
||||
fail_ci_if_error: false
|
||||
|
||||
test-minimal-config:
|
||||
name: Test Minimal Configuration
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install ESPHome
|
||||
run: |
|
||||
pip install --upgrade pip
|
||||
pip install esphome
|
||||
|
||||
- name: Validate minimal config
|
||||
run: |
|
||||
esphome config tests/maidesite_desk/test_maidesite_desk_mini.yaml
|
||||
|
||||
test-full-config:
|
||||
name: Test Full Configuration
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
|
||||
- name: Install ESPHome
|
||||
run: |
|
||||
pip install --upgrade pip
|
||||
pip install esphome
|
||||
|
||||
- name: Validate full config
|
||||
run: |
|
||||
esphome config tests/maidesite_desk/test_maidesite_desk_full.yaml
|
||||
|
||||
summary:
|
||||
name: Test Summary
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
needs: [test-build, lint-code, lint-python, test-python, test-minimal-config, test-full-config]
|
||||
if: always()
|
||||
steps:
|
||||
- name: Check test results
|
||||
run: |
|
||||
echo "Test Build: ${{ needs.test-build.result }}"
|
||||
echo "Lint C++: ${{ needs.lint-code.result }}"
|
||||
echo "Lint Python: ${{ needs.lint-python.result }}"
|
||||
echo "Python Unit Tests: ${{ needs.test-python.result }}"
|
||||
echo "Minimal Config: ${{ needs.test-minimal-config.result }}"
|
||||
echo "Full Config: ${{ needs.test-full-config.result }}"
|
||||
|
||||
if [ "${{ needs.test-build.result }}" != "success" ] || \
|
||||
[ "${{ needs.lint-code.result }}" != "success" ] || \
|
||||
[ "${{ needs.lint-python.result }}" != "success" ] || \
|
||||
[ "${{ needs.test-python.result }}" != "success" ] || \
|
||||
[ "${{ needs.test-minimal-config.result }}" != "success" ] || \
|
||||
[ "${{ needs.test-full-config.result }}" != "success" ]; then
|
||||
echo "One or more tests failed"
|
||||
exit 1
|
||||
fi
|
||||
echo "All tests passed successfully!"
|
||||
Reference in New Issue
Block a user