forked from dandi/dandisets-linkml-status-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dandi#16 from candleindark/linkml-error-categoriza…
…tion Improve categorization of errors from the LinkML validator
- Loading branch information
Showing
4 changed files
with
213 additions
and
14 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
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,41 @@ | ||
import pytest | ||
|
||
from dandisets_linkml_status_tools.cli.models import JsonschemaValidationErrorType | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("op1", "op2", "expected_result"), | ||
[ | ||
(JsonschemaValidationErrorType("integer", [1, 2]), "hello", False), | ||
( | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("string", 1), | ||
False, | ||
), | ||
( | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("integer", "1"), | ||
False, | ||
), | ||
( | ||
JsonschemaValidationErrorType("integer", 1), | ||
JsonschemaValidationErrorType("integer", 2), | ||
False, | ||
), | ||
( | ||
JsonschemaValidationErrorType("integer", 42), | ||
JsonschemaValidationErrorType("integer", 42), | ||
True, | ||
), | ||
( | ||
JsonschemaValidationErrorType("integer", [1, 2, 3]), | ||
JsonschemaValidationErrorType("integer", [1, 2, 3]), | ||
True, | ||
), | ||
], | ||
) | ||
def test_jsonschema_validation_error_type_equality(op1, op2, expected_result): | ||
""" | ||
Test the equal operator of the `JsonschemaValidationErrorType` class | ||
""" | ||
assert (op1 == op2) == expected_result |
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 |