Add LinkML behavior tests for required: False -> True slot_usage refinement#408
Draft
candleindark wants to merge 8 commits into
Draft
Add LinkML behavior tests for required: False -> True slot_usage refinement#408candleindark wants to merge 8 commits into
candleindark wants to merge 8 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2 tasks
…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>
a0fa5c5 to
4b2f003
Compare
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>
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.
Summary
Adds a detached
linkml-behavior-testhatch env and a newtests/linkml_behavior/tree, which together assert LinkML behavior that the LinkML version ofdandischemarelies on. This PR covers therequired: False -> Trueslot_usagerefinement; the tests live undertests/linkml_behavior/required_refinement/.The env is detached (no
dandischemainstall) and does not pin a LinkML version, so the tests run against the latest LinkML release and surface upstream regressions early.Closes #405.
Checklist
tests/linkml_behavior/required_refinement/against the LinkML schema, usinglinkml-validate.gen-json-schema --title-from title(matching the invocation inpyproject.toml'slinkml-auto-converted:2jsonscript), usingcheck-jsonschema(JSON Schemaformat-keyword checks enabled by default).gen-pydantic --black --template-dir tools/linkml_conversion_tools/pydantic_templates(matching the invocation inpyproject.toml'slinkml-auto-converted:2pydanticscript).master, PR tomaster, manual dispatch, and a daily schedule.tests/linkml_behavior/—linkml-behavior-typing— distinct fromlinkml-behavior-testand from the existing toxtypingenv (which targetsdandischema), plus a GitHub Actions workflow that runs the type-check on push tomasterand PR tomaster.Test plan
hatch run linkml-behavior-test:test— 18 passed locally (Python 3.10,linkml1.11.0).hatch run linkml-behavior-typing:check— no issues found locally.