-
Notifications
You must be signed in to change notification settings - Fork 34
Convert test_referencevalidator.py from unittest to pytest #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Convert test_referencevalidator.py from unittest to pytest #452
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
17727b0
to
fa7005b
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
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 77.38% 77.38%
=======================================
Files 52 52
Lines 4479 4479
Branches 979 979
=======================================
Hits 3466 3466
Misses 785 785
Partials 228 228 ☔ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, use pytest's parametrize here
# for r in report.repaired(): | ||
# print(r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete or turn into a test
assert 0 == len(report.errors()) | ||
assert 0 == len(report.normalized_results()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yoda condition
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. |