-
Notifications
You must be signed in to change notification settings - Fork 2
docs: testing patterns + Python 3.13 deprecation notes (v1.9.1) #38
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
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
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "indigo", | ||
| "version": "1.9.0", | ||
| "version": "1.9.1", | ||
| "description": "Indigo home automation development toolkit \u2014 plugin development, API integration, and control page building", | ||
| "repository": "https://github.com/simons-plugins/indigo-claude-plugin" | ||
| } |
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,134 @@ | ||
| # Testing Patterns | ||
|
|
||
| How to test Indigo plugins. Two complementary patterns: | ||
|
|
||
| - **Pattern A — Unit tests with mocks**: fast, no Indigo runtime required, runs in CI. | ||
| - **Pattern B — Live integration with TestingBase**: exercises a real running Indigo server, catches integration bugs and validates plugin XML. | ||
|
|
||
| They are complementary, not alternatives. Run A often, B before a release. | ||
|
|
||
| --- | ||
|
|
||
| ## Pattern A — Unit tests with a mocked Indigo runtime | ||
|
|
||
| Mock `indigo` via `unittest.mock` and import your plugin module directly. Tests can then exercise business logic — API parsing, state computation, ConfigUI validation, scheduling — without an Indigo install. | ||
|
|
||
| **When to use**: anything that doesn't depend on Indigo's database — most of your plugin's logic. | ||
|
|
||
| **Reference shape**: | ||
|
|
||
| ```python | ||
| # tests/conftest.py | ||
| import sys | ||
| from pathlib import Path | ||
| from unittest.mock import Mock | ||
| import pytest | ||
|
|
||
| SERVER_PLUGIN_DIR = ( | ||
| Path(__file__).parent.parent | ||
| / "MyPlugin.indigoPlugin" | ||
| / "Contents" | ||
| / "Server Plugin" | ||
| ) | ||
| sys.path.insert(0, str(SERVER_PLUGIN_DIR)) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_logger(): | ||
| # Mock() auto-creates these attributes on first access — the explicit | ||
| # assignment is for readability so test failures point at named mocks. | ||
| logger = Mock() | ||
| for level in ("debug", "info", "warning", "error", "exception"): | ||
| setattr(logger, level, Mock()) | ||
| return logger | ||
| ``` | ||
|
|
||
| Tests then import plugin modules and inject `mock_logger` (and other fixtures) where the plugin would normally use `self.logger`. Run with `pytest` — no Indigo running, no credentials, no network. | ||
|
|
||
| --- | ||
|
|
||
| ## Pattern B — Live integration with TestingBase | ||
|
|
||
| Indigo ships [`TestingBase`](https://github.com/IndigoDomotics/TestingBase) as a shared git submodule. Tests subclass `APIBase` — an abstract `unittest.TestCase` — and exercise a running Indigo server's HTTP API. The companion `ValidateXmlFile` helper validates `Devices.xml`, `Actions.xml`, `Events.xml`, and `MenuItems.xml` against the Indigo schema. | ||
|
|
||
| **When to use**: pre-release smoke tests; XML schema validation; end-to-end checks against your plugin's HTTP responder. | ||
|
|
||
| **Setup**: | ||
|
|
||
| ```bash | ||
| # At the top level of your plugin repo | ||
| git submodule add https://github.com/IndigoDomotics/TestingBase.git tests/shared | ||
| git submodule update --init | ||
| ``` | ||
|
|
||
| **Layout** (the convention TestingBase expects): | ||
|
|
||
| ``` | ||
| my-plugin/ | ||
| ├── tests/ | ||
| │ ├── shared/ # submodule — do NOT edit | ||
| │ ├── .env # gitignored — Indigo API credentials | ||
| │ ├── testing-requirements.txt # references shared/module-requirements.txt | ||
| │ ├── venv/ # gitignored — your test venv | ||
| │ └── test_my_plugin.py | ||
| ``` | ||
|
|
||
| `tests/.env` carries credentials — see `tests/shared/ENV_TEMPLATE` for the exact keys. `tests/testing-requirements.txt` should chain to the shared list: | ||
|
|
||
| ``` | ||
| -r shared/module-requirements.txt | ||
| # anything else your tests need | ||
| ``` | ||
|
|
||
| **Minimal `APIBase` test**: | ||
|
|
||
| ```python | ||
| # tests/test_my_plugin.py | ||
| from shared import APIBase | ||
|
|
||
| class TestMyPlugin(APIBase): | ||
| def test_device_reachable(self): | ||
| device = self.get_indigo_object(<device_id>) | ||
| self.assertTrue(device["enabled"]) | ||
| ``` | ||
|
|
||
| **XML validation** — `ValidateXmlFile` MUST come first in the MRO. Resolve the path relative to the test file so the test runs on any machine: | ||
|
|
||
| ```python | ||
| import os | ||
| from shared import APIBase, ValidateXmlFile | ||
|
|
||
| class TestActionsXml(ValidateXmlFile, APIBase): | ||
| server_plugin_dir_path = os.path.abspath( | ||
| os.path.join( | ||
| os.path.dirname(__file__), | ||
| "../MyPlugin.indigoPlugin/Contents/Server Plugin", | ||
| ) | ||
| ) | ||
| file_name = "Actions.xml" | ||
| ``` | ||
|
|
||
| **Maintenance**: `tests/shared` is a submodule. Pull updates with | ||
| `git submodule update --recursive --remote tests/shared` and never commit | ||
| local changes back to it — the upstream README is explicit about that. | ||
|
|
||
| --- | ||
|
|
||
| ## Choosing between A and B | ||
|
|
||
| | | Pattern A (mocks) | Pattern B (TestingBase) | | ||
| |---|---|---| | ||
| | Speed | Seconds | Slower — HTTP round-trips per assertion; helpers like `run_host_script` spawn an IPH3 process per call | | ||
| | Indigo install needed | No | Yes — running server + admin API access | | ||
| | What it catches | Logic errors | Integration + XML schema errors | | ||
| | Best for | CI on every PR | Pre-release smoke | | ||
|
|
||
| Use both for any non-trivial plugin: A on every commit, B before each release. | ||
|
|
||
| --- | ||
|
|
||
| ## References | ||
|
|
||
| - TestingBase upstream: https://github.com/IndigoDomotics/TestingBase | ||
| - Plugin HTTP API (consumed by Pattern B): see `/indigo:api` | ||
| - Plugin lifecycle (what you'd typically test): see `concepts/plugin-lifecycle.md` | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add language identifiers to unlabeled fenced code blocks (MD040).
markdownlint-cli2 is flagging fenced blocks without a language at Line 64 and Line 76. Add a language tag (e.g.,
text) to avoid lint failures and improve readability.✅ Proposed fix
...
-
+text-r shared/module-requirements.txt
anything else your tests need
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 64-64: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
[warning] 76-76: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents