-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on the `validator` and `validator_value` fields from JSON schema validation errors
- Loading branch information
1 parent
d9afd97
commit c22f7c3
Showing
2 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
from jsonschema.exceptions import ValidationError | ||
from linkml.validator.report import Severity, ValidationResult | ||
|
||
from dandisets_linkml_status_tools.cli.models import JsonschemaValidationErrorType | ||
from dandisets_linkml_status_tools.cli.tools import get_linkml_err_counts | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("error_types", "expected_counts"), | ||
[ | ||
([], []), | ||
( | ||
[ | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("integer", 2), | ||
JsonschemaValidationErrorType("string", "hello"), | ||
], | ||
[ | ||
(JsonschemaValidationErrorType("integer", 1), 1), | ||
(JsonschemaValidationErrorType("integer", 2), 1), | ||
(JsonschemaValidationErrorType("string", "hello"), 1), | ||
], | ||
), | ||
( | ||
[ | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("integer", 1), | ||
], | ||
[(JsonschemaValidationErrorType("integer", 1), 3)], | ||
), | ||
( | ||
[ | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("string", "hello"), | ||
JsonschemaValidationErrorType("string", "hello"), | ||
JsonschemaValidationErrorType("integer", 2), | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("array", [1, 2, 3]), | ||
JsonschemaValidationErrorType("array", (1, 2, 3)), | ||
], | ||
[ | ||
(JsonschemaValidationErrorType("array", [1, 2, 3]), 1), | ||
(JsonschemaValidationErrorType("array", (1, 2, 3)), 1), | ||
(JsonschemaValidationErrorType("integer", 1), 2), | ||
(JsonschemaValidationErrorType("integer", 2), 1), | ||
(JsonschemaValidationErrorType("string", "hello"), 2), | ||
], | ||
), | ||
], | ||
) | ||
def test_get_linkml_err_counts( | ||
error_types: list[JsonschemaValidationErrorType], | ||
expected_counts: list[tuple[JsonschemaValidationErrorType, int]], | ||
): | ||
""" | ||
Test the `get_linkml_err_counts` function | ||
:param error_types: A list of JSON schema validation error types | ||
:param expected_counts: A list of tuples of JSON schema validation error types | ||
and their expected counts | ||
""" | ||
errs = [] | ||
for t in error_types: | ||
# noinspection PyTypeChecker | ||
jsonschema_validation_error = ValidationError( | ||
message="An artificial error", | ||
validator=t.validator, | ||
validator_value=t.validator_value, | ||
) | ||
validation_result = ValidationResult( | ||
type="jsonschema", | ||
severity=Severity.ERROR, | ||
message="What need to be fixed", | ||
source=jsonschema_validation_error, | ||
) | ||
errs.append(validation_result) | ||
|
||
counts = get_linkml_err_counts(errs) | ||
assert counts == expected_counts |