Skip to content

Add LinkML behavior tests for required: False -> True slot_usage refinement#408

Draft
candleindark wants to merge 8 commits into
linkml-conversionfrom
gh-405-linkml-behavior-test
Draft

Add LinkML behavior tests for required: False -> True slot_usage refinement#408
candleindark wants to merge 8 commits into
linkml-conversionfrom
gh-405-linkml-behavior-test

Conversation

@candleindark
Copy link
Copy Markdown
Member

@candleindark candleindark commented May 13, 2026

Summary

Adds a detached linkml-behavior-test hatch env and a new tests/linkml_behavior/ tree, which together assert LinkML behavior that the LinkML version of dandischema relies on. This PR covers the required: False -> True slot_usage refinement; the tests live under tests/linkml_behavior/required_refinement/.

The env is detached (no dandischema install) and does not pin a LinkML version, so the tests run against the latest LinkML release and surface upstream regressions early.

Closes #405.

Checklist

  • Validate the data instances in tests/linkml_behavior/required_refinement/ against the LinkML schema, using linkml-validate.
  • Validate the data instances against the JSON Schema generated from the LinkML schema via gen-json-schema --title-from title (matching the invocation in pyproject.toml's linkml-auto-converted:2json script), using check-jsonschema (JSON Schema format-keyword checks enabled by default).
  • Validate the data instances against the Pydantic models generated from the LinkML schema via gen-pydantic --black --template-dir tools/linkml_conversion_tools/pydantic_templates (matching the invocation in pyproject.toml's linkml-auto-converted:2pydantic script).
  • Add a GitHub Actions workflow that runs the LinkML behavior tests on push to master, PR to master, manual dispatch, and a daily schedule.
  • Add a separate hatch env for static type-checking of tests/linkml_behavior/linkml-behavior-typing — distinct from linkml-behavior-test and from the existing tox typing env (which targets dandischema), plus a GitHub Actions workflow that runs the type-check on push to master and PR to master.

Test plan

  • hatch run linkml-behavior-test:test — 18 passed locally (Python 3.10, linkml 1.11.0).
  • hatch run linkml-behavior-typing:check — no issues found locally.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.83%. Comparing base (a0cdc4a) to head (7aa10b7).

Additional details and impacted files
@@                  Coverage Diff                  @@
##           linkml-conversion     #408      +/-   ##
=====================================================
+ Coverage              96.67%   97.83%   +1.16%     
=====================================================
  Files                     20       19       -1     
  Lines                   2436     2407      -29     
=====================================================
  Hits                    2355     2355              
+ Misses                    81       52      -29     
Flag Coverage Δ
unittests 97.83% <ø> (+1.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

candleindark and others added 3 commits May 13, 2026 23:50
…finement

Adds a detached hatch env (`linkml-behavior-test`) and a new test tree
(`tests/linkml_behavior/`) asserting that `linkml-validate` honors a
`slot_usage` entry that tightens an inherited slot's `required` from
`False` to `True` while preserving the slot's other inherited
constraints (here, `range`). This is the LinkML behavior the LinkML
version of `dandischema` relies on; see issue #405.

The env is detached (no dandischema install) with only `linkml` and
`pytest` as dependencies, and it does not pin a LinkML version so the
tests run against the latest release and surface upstream regressions
early. The new directory carries its own `pytest.toml` so pytest's
config-file discovery stops there and does not inherit the repo-root
`tox.ini` `[pytest]` section, which is tailored to the `dandischema`
package test suite.

A follow-up will add a GitHub Actions workflow that invokes the hatch
env so the same checks run in CI.

Co-Authored-By: Claude Code 2.1.139 / Claude Opus 4.7 claude-opus-4-7 <noreply@anthropic.com>
Extends the `required_refinement` behavior tests to also assert that the
JSON Schema produced by running `gen-json-schema --title-from title`
against `schema.yaml` (matching the invocation in `pyproject.toml`'s
`linkml-auto-converted:2json` script) honors the `required: False -> True`
`slot_usage` refinement while preserving the inherited `range` constraint.
Validation is performed via the `check-jsonschema` CLI, which has JSON
Schema `format` keyword validation enabled by default.

Adds a `conftest.py` with two session-scoped fixtures:

- `json_schemas` — per-target-class JSON schemas generated once from
  `schema.yaml`.
- `json_instances` — the YAML data instances converted once to JSON.

The detached `linkml-behavior-test` hatch env now also depends on
`check-jsonschema` and `PyYAML`.

Co-Authored-By: Claude Code 2.1.139 / Claude Opus 4.7 claude-opus-4-7 <noreply@anthropic.com>
The `test_validate.py` and `test_json_schema_validate.py` files exercise
the same six `(target_class, instance)` cases against different
validators. Move the case lists into a shared `_cases.py` so adding or
adjusting a case updates both test files at once.

Co-Authored-By: Claude Code 2.1.141 / Claude Opus 4.7 claude-opus-4-7 <noreply@anthropic.com>
@candleindark candleindark force-pushed the gh-405-linkml-behavior-test branch from a0fa5c5 to 4b2f003 Compare May 14, 2026 06:51
candleindark and others added 5 commits May 14, 2026 22:29
Add `test_pydantic_validate.py`, mirroring `test_validate.py` and
`test_json_schema_validate.py`. A new session-scoped `pydantic_module`
fixture runs `gen-pydantic --black --template-dir <...>` (matching the
invocation in the `linkml-auto-converted:2pydantic` script) and loads
the generated module dynamically; the new `instance_data` fixture
provides YAML instances parsed into Python dicts for `model_validate`.
The dynamically-loaded module is registered in `sys.modules` under a
topic-folder-suffixed name so future sibling fixtures don't collide.

Also add `black` and `pydantic` to the `linkml-behavior-test` env so
`--black` formatting works and `pydantic.ValidationError` is importable.

Co-Authored-By: Claude Code 2.1.141 / Claude Opus 4.7 claude-opus-4-7 <noreply@anthropic.com>
Set version environment to 3.10. The
lowest currently supported Python
Runs the `tests/linkml_behavior/` suite under the `linkml-behavior-test`
hatch env on push/PR to `master`, on a daily 06:00 UTC schedule, and on
manual dispatch. The env doesn't pin a LinkML version, so the daily
schedule surfaces upstream LinkML regressions early.

Co-Authored-By: Claude Code 2.1.141 / Claude Opus 4.7 claude-opus-4-7 <noreply@anthropic.com>
The env provides `hatch run linkml-behavior-typing:check`, which runs
`mypy --install-types --non-interactive` over `tests/linkml_behavior/`.
It is kept distinct from `linkml-behavior-test` and from the tox
`typing` env (which targets `dandischema`).

Co-Authored-By: Claude Code 2.1.141 / Claude Opus 4.7 claude-opus-4-7 <noreply@anthropic.com>
Runs `hatch run linkml-behavior-typing:check` on push/PR to `master`.
No cron — typing breakages from upstream stub or library releases are
rare and typically don't cause runtime errors.

Co-Authored-By: Claude Code 2.1.141 / Claude Opus 4.7 claude-opus-4-7 <noreply@anthropic.com>
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