-
Notifications
You must be signed in to change notification settings - Fork 6
Unit Tests for Maidesite Desk #34
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9ba21ad
Add comprehensive tests and CI workflow for Maidesite Desk component
ElVit 24d6b94
Remove update_interval from maidesite_desk test configuration
ElVit 3714ed8
Added #ifdef for sensors and numbers
ElVit 62bcbe8
Potential fix for pull request finding 'CodeQL / Workflow does not co…
ElVit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| 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: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| 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: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| 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: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| 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: | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| 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!" | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Testing Documentation for Maidesite Desk Component | ||
|
|
||
| This directory contains comprehensive tests for the `maidesite_desk` ESPHome component. | ||
|
|
||
| ## Test Structure | ||
|
|
||
| ### Unit Tests (`test_maidesite_desk_unit.py`) | ||
|
|
||
| - Tests Python configuration validation | ||
| - Tests component metadata (CODEOWNERS, DEPENDENCIES, etc.) | ||
| - Tests configuration schema structure | ||
| - Tests all platform imports (sensor, number, button) | ||
| - Tests code generation logic | ||
|
|
||
| ### Integration Tests (`test_maidesite_desk_integration.py`) | ||
|
|
||
| - Tests minimal feature configuration on ESP32 board | ||
| - Tests full feature configuration on ESP32 board | ||
| - Tests configuration on ESP32-S2 board | ||
| - Tests configuration on ESP32-C3 board | ||
|
|
||
| ### Test Configuration Files | ||
|
|
||
| - `test_maidesite_desk_esp32s2.yaml` - ESP32-S2 Wemos S2 Mini | ||
| - `test_maidesite_desk_esp32c3.yaml` - ESP32-C3 mini (RISC-V) | ||
| - `test_maidesite_desk_mini.yaml` - Minimal ESP32 configuration for basic testing | ||
| - `test_maidesite_desk_full.yaml` - Comprehensive ESP32 configuration with all features | ||
|
|
||
| ## Running Tests Locally | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| ```bash | ||
| pip install -r ../requirements.txt | ||
| ``` | ||
|
|
||
| ### Run All Tests | ||
|
|
||
| ```bash | ||
| pytest tests/maidesite_desk/ -v | ||
| ``` | ||
|
|
||
| ### Run Only Unit Tests | ||
|
|
||
| ```bash | ||
| pytest tests/maidesite_desk/test_maidesite_desk_unit.py -v | ||
| ``` | ||
|
|
||
| ### Run Only Integration Tests | ||
|
|
||
| ```bash | ||
| pytest tests/maidesite_desk/test_maidesite_desk_integration.py -v | ||
| ``` | ||
|
|
||
| ### Run with Coverage | ||
|
|
||
| ```bash | ||
| pytest tests/maidesite_desk/ --cov=components.maidesite_desk --cov-report=html | ||
| ``` | ||
|
|
||
| ## Test Coverage | ||
|
|
||
| The test suite covers: | ||
|
|
||
| - Component configuration validation | ||
| - All sensor entities (height_abs, height_pct, height_min, height_max, position_m1-m4) | ||
| - All number entities (height_abs, height_pct) | ||
| - All button entities (stop, step_up, step_down, goto_max, goto_min, goto_m1-m4, save_m1-m4) | ||
| - Multiple ESP32 board variants (ESP32, ESP32-S2, ESP32-C3) | ||
| - Minimal and full configuration scenarios | ||
|
|
||
| ## CI/CD Integration | ||
|
|
||
| These tests are designed to run in GitHub Actions CI/CD pipelines. See `.github/workflows/test_maidesite_desk.yml` for the workflow configuration. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.