-
Notifications
You must be signed in to change notification settings - Fork 4
Adds wrapper code for ClassList routines in Project #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
231b18a
Adds code to wrap ClassLists and force revalidation
DrPaulSharp 4ee3d1c
Adds auxiliary routines to "classlist.py" to allow iadd, set and del …
DrPaulSharp 9a244a9
Adds "_setattr" auxiliary routine to each model in "models.py"
DrPaulSharp 52175c3
Wraps the "_setattr" auxiliary routine for each model that requires c…
DrPaulSharp 0bcaf18
Adds module "CustomErrors.py", including routine "formatted_pydantic_…
DrPaulSharp 62f950c
Removed code to wrap "__setattr__" in models.py
DrPaulSharp c099632
Adds tests for wrapping code.
DrPaulSharp b421caf
Tidies up the "Project.check_allowed_values()" routine
DrPaulSharp 22aeb63
Adds tests requiring testing equality of Data models.
DrPaulSharp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| """Defines routines for custom error handling in RAT.""" | ||
|
|
||
| from pydantic import ValidationError | ||
|
|
||
|
|
||
| def formatted_pydantic_error(error: ValidationError) -> str: | ||
| """Write a custom string format for pydantic validation errors. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| error : pydantic.ValidationError | ||
| A ValidationError produced by a pydantic model | ||
|
|
||
| Returns | ||
| ------- | ||
| error_str : str | ||
| A string giving details of the ValidationError in a custom format. | ||
| """ | ||
| num_errors = error.error_count() | ||
| error_str = f'{num_errors} validation error{"s"[:num_errors!=1]} for {error.title}' | ||
| for this_error in error.errors(): | ||
| error_str += '\n' | ||
| if this_error['loc']: | ||
| error_str += ' '.join(this_error['loc']) + '\n' | ||
| error_str += ' ' + this_error['msg'] | ||
| return error_str |
This file contains hidden or 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 hidden or 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,20 @@ | ||
| """Test the utils.custom_errors module.""" | ||
|
|
||
| from pydantic import create_model, ValidationError | ||
| import pytest | ||
|
|
||
| import RAT.utils.custom_errors | ||
|
|
||
|
|
||
| def test_formatted_pydantic_error() -> None: | ||
| """When a pytest ValidationError is raised we should be able to take it and construct a formatted string.""" | ||
|
|
||
| # Create a custom pydantic model for the test | ||
| TestModel = create_model('TestModel', int_field=(int, 1), str_field=(str, 'a')) | ||
|
|
||
| with pytest.raises(ValidationError) as exc_info: | ||
| TestModel(int_field='string', str_field=5) | ||
|
|
||
| error_str = RAT.utils.custom_errors.formatted_pydantic_error(exc_info.value) | ||
| assert error_str == ('2 validation errors for TestModel\nint_field\n Input should be a valid integer, unable to ' | ||
| 'parse string as an integer\nstr_field\n Input should be a valid string') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.