Skip to content

Add unit tests for base helper modules#797

Merged
cybermaggedon merged 1 commit intotrustgraph-ai:masterfrom
zeel2104:test/base-module-coverage-792
Apr 14, 2026
Merged

Add unit tests for base helper modules#797
cybermaggedon merged 1 commit intotrustgraph-ai:masterfrom
zeel2104:test/base-module-coverage-792

Conversation

@zeel2104
Copy link
Copy Markdown
Contributor

Summary

  • add unit tests for base metrics, logging, spec, parameter_spec, and flow modules
  • add a lightweight test-only module loader so these tests can run without optional runtime dependencies
  • fix Parameter.start/stop to accept self

Testing

  • python -m pytest -c nul tests/unit/test_base/test_metrics.py tests/unit/test_base/test_logging.py tests/unit/test_base/test_flow_base_modules.py

Closes #792

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

Contributor License Agreement ✅

All contributors have signed the CLA. Thank you!

@zeel2104
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@cybermaggedon cybermaggedon self-requested a review April 13, 2026 22:33
@cybermaggedon cybermaggedon self-assigned this Apr 13, 2026
Copy link
Copy Markdown
Contributor

@cybermaggedon cybermaggedon left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Can you remove the customer loader, and pytest.importorskip("pytest") and this is good to merge.

Comment thread tests/unit/test_base/test_metrics.py Outdated
from tests.unit.test_base._module_loader import load_base_module


pytest.importorskip("pytest")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggest deleting this. This module runs under pytest, so if this code is executing, pytest is running.

Comment thread tests/unit/test_base/_module_loader.py Outdated
from pathlib import Path


BASE_DIR = Path(__file__).resolve().parents[3] / "trustgraph-base" / "trustgraph" / "base"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The custom loader is unnecessary, and extends risks of executing unwanted code in the CI pipeline. We want to be very 100% that the tests are testing the right code, so the procedure is that you install the packages and then execute the tests.

e.g.

python3 -m venv env
. env/bin/activate
# This is the subset of packages the tests extend over
pip install ./trustgraph-{base,cli,flow,vertexai,bedrock,unstructured}

And then you can run the tests...

pytest tests/unit
pytest tests/integration -m 'not slow'
pytest tests/contract

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Btw, there's something faulty about pip install -e for these packages, if you're used to using that. It doesn't work because they share a 'trustgraph' namespace, which pip install -e doesn't know how to deal yet.

@zeel2104 zeel2104 force-pushed the test/base-module-coverage-792 branch from d8c469e to 4e63dbd Compare April 13, 2026 23:06
@zeel2104
Copy link
Copy Markdown
Contributor Author

@cybermaggedon
Removed the custom loader and pytest.importorskip, and updated the tests to import the package directly. Verified with:

python -m pytest -o addopts="" tests/unit/test_base/test_metrics.py tests/unit/test_base/test_logging.py tests/unit/test_base/test_flow_base_modules.py

Copy link
Copy Markdown
Contributor

@cybermaggedon cybermaggedon left a comment

Choose a reason for hiding this comment

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

Both issues fixed. Custom module loader is gone — all three files use normal imports. pytest.importorskip("pytest") is gone. The parameter_spec.py bug fix (adding self to start/stop) is still included. Good to merge.

@cybermaggedon
Copy link
Copy Markdown
Contributor

Tests are failing, but that's because we're tracking some new changes on master from the v2.2 / v2.3 development. Merging this, because merging onto a release branch will likely fix most of this.

@cybermaggedon cybermaggedon merged commit 19f73e4 into trustgraph-ai:master Apr 14, 2026
2 of 3 checks passed
cybermaggedon pushed a commit that referenced this pull request Apr 14, 2026
- add unit tests for base metrics, logging, spec, parameter_spec,
  and flow modules
- add a lightweight test-only module loader so these tests can run
  without optional runtime dependencies
- fix Parameter.start/stop to accept self
@cybermaggedon
Copy link
Copy Markdown
Contributor

Thanks for the additional test coverage, much appreciated! ❤️

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.

Add unit tests for untested base modules

2 participants