Validate and JSON Serialize validate_types.Severity instances by name#1624
Validate and JSON Serialize validate_types.Severity instances by name#1624yarikoptic merged 3 commits intodandi:masterfrom
validate_types.Severity instances by name#1624Conversation
97aaf9a to
6cc665c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1624 +/- ##
===========================================
+ Coverage 64.10% 88.90% +24.79%
===========================================
Files 82 83 +1
Lines 11400 11505 +105
===========================================
+ Hits 7308 10228 +2920
+ Misses 4092 1277 -2815
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:
|
|
please add a basic test for serialization of the ValidationResult into json and verify that Severity is literal, and that we can load from json back into |
6cc665c to
597c303
Compare
8c439d2 to
9d61528
Compare
validate_types.Severity instances by their namevalidate_types.Severity instances by name
16c7c63 to
7e7ef88
Compare
There was a problem hiding this comment.
Pull Request Overview
Adds support for validating Severity enum members by their name strings and ensuring JSON serialization outputs those names.
- Introduces a dynamic
_SeverityNameenum to represent member names in JSON schema. - Implements
_accept_severity_by_nameand wrapsSeverityin anAnnotatedaliasSeverity_withBeforeValidatorandPlainSerializer. - Updates
ValidationResult.severityto useSeverity_and extends tests accordingly.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dandi/validate_types.py | Define _SeverityName, _accept_severity_by_name, Severity_, and update field. |
| dandi/tests/test_validate_types.py | Add tests covering serialization, round-trip, integer input, and invalid values. |
Comments suppressed due to low confidence (1)
dandi/tests/test_validate_types.py:121
- There are tests for integer and invalid inputs, but none explicitly verifying that a valid severity name string (like
'ERROR') is accepted and correctly mapped. Add a test case to ensure string names round-trip as intended.
@pytest.mark.parametrize("invalid_severity", ["foo", 42, True])
3261c34 to
7e7ef88
Compare
|
ready for review @candleindark ? |
…ity` instances by name This allows the data to be handled by human more readily
…sult.origin_result` Doing this eliminates false warnings in PyCharm
7e7ef88 to
b3854d4
Compare
Yes. It is ready now. |
|
🚀 PR was released in |
This PR allows validation and JSON serialization of
validate_types.Severityinstances by name. It allows the represented data byvalidate_types.Severityto be more readily interpreted and generated by human users. This PR closes #1608.Remaining TODOs:
validate_types.Severity#1622. Make sure to rebase/merge with master after Correct logic handling the values ofvalidate_types.Severity#1622 is merged to master to get the relevant commits.