Add support for module tests#39
Open
xsedla1o wants to merge 8 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds lightweight dp3.testing utilities for unit-testing secondary module hook behavior without running a full DP3 instance, along with validation to reject no-op DataPointTasks and documentation for the new workflow.
Changes:
- Introduces
DP3ModuleTestCase, assertion helpers, config helpers, and a capturing test callback registrar. - Adds empty
DataPointTaskvalidation while preserving internal synthetic-task creation. - Documents module testing and adds tests/config fixtures for the new utilities.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
dp3/testing/__init__.py |
Exposes the new testing API. |
dp3/testing/assertions.py |
Adds task/datapoint/record assertion helpers. |
dp3/testing/case.py |
Adds the DP3ModuleTestCase harness and hook runner helpers. |
dp3/testing/config.py |
Adds helpers for loading DP3 test configuration. |
dp3/testing/registrar.py |
Adds a test registrar that captures and runs module hook registrations. |
dp3/common/task.py |
Adds validation rejecting empty DataPointTasks unless explicitly allowed. |
dp3/common/callback_registrar.py |
Allows internal synthetic empty tasks for snapshot hook wrappers. |
dp3/task_processing/task_executor.py |
Allows internal synthetic empty tasks for entity-creation refresh. |
tests/test_common/test_module_testing.py |
Adds coverage for the new module testing utilities. |
tests/test_config/db_entities/test_entity_type.yml |
Adds a timeseries fixture attribute for tests. |
docs/howto/test-module.md |
Adds the module testing how-to guide. |
docs/hooks.md |
Documents the new non-empty returned task requirement. |
docs/modules.md |
Links module docs to the new testing guide. |
mkdocs.yml |
Adds the new how-to page to documentation navigation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+151
to
+160
| reg = HookRegistration( | ||
| kind="on_entity_creation", | ||
| entity=entity, | ||
| hook=hook, | ||
| refresh=refresh, | ||
| may_change=copy.deepcopy(may_change or []), | ||
| ) | ||
| self._record(reg) | ||
| self._on_creation_hooks[entity].append(reg) | ||
|
|
Comment on lines
+172
to
+180
| reg = HookRegistration( | ||
| kind="on_new_attr", | ||
| hook_type=hook_type, | ||
| entity=entity, | ||
| attr=attr, | ||
| hook=hook, | ||
| refresh=refresh, | ||
| may_change=copy.deepcopy(may_change or []), | ||
| ) |
Comment on lines
+286
to
+294
| reg = HookRegistration( | ||
| kind="periodic_update", | ||
| hook=hook, | ||
| hook_id=hook_id, | ||
| entity_type=entity_type, | ||
| period=period, | ||
| ) | ||
| self._record(reg) | ||
| self._periodic_record_hooks[entity_type, hook_id].append(reg) |
Comment on lines
+300
to
+308
| reg = HookRegistration( | ||
| kind="periodic_eid_update", | ||
| hook=hook, | ||
| hook_id=hook_id, | ||
| entity_type=entity_type, | ||
| period=period, | ||
| ) | ||
| self._record(reg) | ||
| self._periodic_eid_hooks[entity_type, hook_id].append(reg) |
| tasks = self.run_periodic_update( | ||
| "service", | ||
| "192.0.2.1:443", | ||
| {"guessed_type": "https"}, |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds lightweight testing utilities for DP3 secondary modules so app developers can unit-test module hook behavior without running a full DP3 instance.
Secondary modules were difficult to test because they normally depend on DP3 runtime wiring. This branch provides a
unittest-friendly harness that loads real app entity config, captures hook registrations, and lets tests invoke hooks directly with validated DP3 task/datapoint objects.Examples
To showcase potential usefulness of such helpers, usable test suites were drafted for select internal apps:
Changes
dp3.testinghelpers, centered aroundDP3ModuleTestCase.hooks.
DataPointTasks that would do no work, while preserving internal synthetic-task use cases.