Skip to content

Add support for module tests#39

Open
xsedla1o wants to merge 8 commits into
masterfrom
module-tests
Open

Add support for module tests#39
xsedla1o wants to merge 8 commits into
masterfrom
module-tests

Conversation

@xsedla1o
Copy link
Copy Markdown
Collaborator

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:

  • ADiCT
  • Amfora (tests pass when this branch of DP3 is installed, CI fails as installs from main)
  • NERD2

Changes

  • Added dp3.testing helpers, centered around DP3ModuleTestCase.
  • Added fake/capturing callback registrar for module hook registration tests.
  • Added helpers for building tasks/datapoints, running hooks, scheduler callbacks, updater hooks, and snapshot/correlation
    hooks.
  • Added assertion helpers for emitted tasks/datapoints and mutated snapshot records.
  • Added timeseries datapoint test helper.
  • Documented module testing workflow in docs.
  • Added tests covering the new utilities.
  • Added validation preventing empty DataPointTasks that would do no work, while preserving internal synthetic-task use cases.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DataPointTask validation 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 thread dp3/testing/registrar.py
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 thread dp3/testing/registrar.py
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 thread dp3/testing/registrar.py
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 thread dp3/testing/registrar.py
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)
Comment thread docs/howto/test-module.md
tasks = self.run_periodic_update(
"service",
"192.0.2.1:443",
{"guessed_type": "https"},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants