Convert test_referencevalidator.py from unittest to pytest#452
Convert test_referencevalidator.py from unittest to pytest#452vladistan wants to merge 1 commit intolinkml:mainfrom
Conversation
vladistan
commented
Sep 4, 2025
- Convert class-level setup/teardown to validation_doc pytest fixture
- Convert helper methods to standalone functions (_get_normalizer, _assert_unrepaired_types_the_same)
- Convert all 14 test methods to standalone functions with validation_doc fixture
fa7005b to
fcbfb72
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #452 +/- ##
=======================================
Coverage 78.41% 78.41%
=======================================
Files 52 52
Lines 4536 4536
Branches 989 989
=======================================
Hits 3557 3557
Misses 764 764
Partials 215 215 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| doc.text("This document describes the validation suite for the LinkML model.") | ||
| doc.h2("Core schema") | ||
| doc.text("Most tests use the core minimal test schema:") | ||
| def _get_normalizer(sb: Optional[SchemaBuilder] = None) -> ReferenceValidator: |
There was a problem hiding this comment.
can you from __future__ import annotations and then use the modern syntax:
sb: SchemaBuilder | None = None| cases = [ | ||
| (SlotDefinition("s", multivalued=False), CollectionForm.NonCollection), |
There was a problem hiding this comment.
all this can be shifted into pytest.mark.parametrize
| expected_unrepaired_vals = [_as_type(v) for v in expected_unrepaired] | ||
| unrepaired_problem_types_vals = [_as_type(v) for v in unrepaired_problem_types] |
There was a problem hiding this comment.
I'd just create sets here - then you don't have to worry about sorting them in the next line
| obj_simple = {"id": "id1", "name": "name1"} | ||
| # cases = form, slot, examples | ||
| # example = input, expected_repairs, expected_unrepaired, expected_output | ||
| cases = [ |
There was a problem hiding this comment.
again, use pytest's parametrize here
| # for r in report.repaired(): | ||
| # print(r) |
There was a problem hiding this comment.
delete these bits of commented-out code
| for r in report.results_excluding_normalized(): | ||
| print(yaml_dumper.dumps(r)) |
There was a problem hiding this comment.
delete print statements or turn them into tests
| for r in report.results_excluding_normalized(): | ||
| print(yaml_dumper.dumps(r)) |
There was a problem hiding this comment.
delete or turn into a test
| assert 0 == len(report.errors()) | ||
| assert 0 == len(report.normalized_results()) |
|
I didn't look in detail at all of the tests, but there's a lot of code here that can be converted into pytest parameters instead of iterating through it in the unit test. |
cmungall
left a comment
There was a problem hiding this comment.
@vladistan do you think you'd be able to work switch to parametrizing these?
31b5cf8 to
b898da9
Compare
3fa5116 to
327f528
Compare
|
@vladistan Could you try to get the parametrize work into this PR this week? We'd like to get as many of these PRs merged before our big mono-repo merge between linkml and linkml-runtime |
|
I have moved the work for this PR from the contributor fork to the linkml-runtime branch https://github.com/linkml/linkml-runtime/tree/convert-test-reference-validator-to-pytest . These branches will be lifted over in the merge to the mono-repo so you won't lose you work. You will need to open a new PR against the linkml monorepo after the move. I'd prefer to get this in but if we can't please open a new PR when you resume work. Thanks! |
57fddd7 to
26228e9
Compare
- Convert class-level setup/teardown to validation_doc pytest fixture - Convert helper methods to standalone functions (_get_normalizer, _assert_unrepaired_types_the_same) - Convert all 14 test methods to standalone functions with validation_doc fixture
26228e9 to
49218b2
Compare