Skip to content

test: expand test coverage - #29

Draft
Alexander-Auer wants to merge 35 commits into
DIRACGrid:mainfrom
Alexander-Auer:stack/test-expansion
Draft

Alexander-Auer wants to merge 35 commits into
DIRACGrid:mainfrom
Alexander-Auer:stack/test-expansion

Conversation

@Alexander-Auer

@Alexander-Auer Alexander-Auer commented Oct 20, 2026 •

Copy link
Copy Markdown

test: expand unit test coverage to every logical case

Important

**Depends on #28 . Merge after #28 ** (PR 3 of 4; the full order is listed in #27).
Until #REGISTRY is merged, this diff also shows the earlier PRs. This PR's own change is one commit:
9dac6f5

This PR adds tests only, apart from enabling coverage measurement. No library code changes.

What is covered

Configuration: a field × kind matrix (test_config.py). Two tables define the five configuration shapes (arc, htcondor-ce, cloud, batch+local, batch+ssh) and which fields apply to each. From them, the tests generate every combination and check that:

  • each field is refused, by name, wherever it doesn't apply;
  • each optional field is accepted wherever it applies, and its value actually reaches the backend's settings;
  • each required field is named when it is missing.

Two guard tests fail if a field or kind is added to BackendConfig without being added to the tables. There are also tests for:

  • the defaults of each shape;
  • every auth combination, valid and invalid;
  • every number field refusing 0 and -1;
  • choices being case-sensitive;
  • error messages reporting every problem at once, without pydantic noise.

The fake backend (test_fake_backend.py):

  • every operation × closed and unavailable;
  • every per-job operation × unknown id, other resource, other backend, injected failure, and an empty batch;
  • kill, output and diagnostics × every job status;
  • what submit actually stores: local inputs read once at submit, URLs left to the resource, and per-copy secrets and environment;
  • every staging and container accept/refuse case, purge followed by every other operation, and an escape attempt writing nothing at all.

Models and smoke tests:

  • JobHandle.key escaping;
  • defaults;
  • that the JobStatus values stay stable, since stored statuses are compared by value;
  • an unparametrised OpOutcome;
  • the version fallback when the package is not installed.

Tooling

  • pytest-cov in the testing extras.
  • [tool.coverage]: branch coverage, subprocesses measured too, and protocol ... bodies and TYPE_CHECKING blocks excluded.
pixi run -e py313 pytest --cov

With this PR, line and branch coverage of src/intercede is 100%. A coverage gate (fail_under) is not added; whether to enforce one is a decision for the team.

477 tests pass on Python 3.11 and 3.13, and pre-commit passes.

alexander and others added 30 commits October 2, 2026 16:54
* feat: Models the core contract needs

* Feat: Protocols and Exceptions added for the core contract

* Feat: Private protocols for the BatchBackend

* feat: a fake backend to run unit tests against

* fix: some code cleanup in the helper functions

* feat: setup for the unit test suite

* chore: style fix

* chore: styling, unit test fixture

* chore: single letter var `h` refering to hanlde changed to `handle`

* fix: unused parameter in `test_injected_failure_is_reported_per_job()` removed

* feat: Models the core contract needs

* Feat: Protocols and Exceptions added for the core contract

* Feat: Private protocols for the BatchBackend

* feat: a fake backend to run unit tests against

* fix: some code cleanup in the helper functions

* feat: setup for the unit test suite

* chore: style fix

* chore: styling, unit test fixture

* chore: single letter var `h` refering to hanlde changed to `handle`

* fix: unused parameter in `test_injected_failure_is_reported_per_job()` removed

* fix: made the OutputSpec optional as it is not suppoerted by all and a consumer should choose to use it or not

---------

Co-authored-by: alexander <alexander.auer@cern.ch>
alexander and others added 5 commits October 9, 2026 16:13
Add BackendConfig, one flat public model a consumer uses to describe any
backend (kind, transport, scheduler, endpoint, host, ...). It is resolved
internally into the settings of exactly one backend family, so a field that
does not apply to the chosen kind is refused by name instead of ignored.

Add the registry: registry.backend(config) builds the backend a
configuration describes, from closed name -> "module:Class" tables. Entries
are imported lazily and every built object is checked against its protocol,
so a broken entry fails at resolution with a RegistryError.

Part of DIRACGrid#18.

Co-authored-by: alexander <alexander.auer@cern.ch>
Cover every field against every backend kind, every fake-backend operation
against every job state, and the remaining registry and model paths. Add
pytest-cov with branch coverage, measured in subprocesses too.

Co-authored-by: alexander <alexander.auer@cern.ch>

This branch has not been deployed

No deployments
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.

1 participant