-
Notifications
You must be signed in to change notification settings - Fork 9
Permit coverage JSON strings and objects #74
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
Conversation
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.
Just made a minor comment, LGTM otherwise
p3analysis/data/_validation.py
Outdated
instance = json.loads(json_string) | ||
if isinstance(json_data, str): | ||
instance = json.loads(json_data) | ||
else: |
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.
Do you want to also type check for dict
or list
? And throw an exception for anything else
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.
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.
Pull Request Overview
This PR allows the coverage validation routine to accept both JSON strings and JSON objects, thereby relaxing input restrictions and updating tests accordingly.
- Updated tests to verify that both JSON strings and objects pass validation.
- Adjusted exception handling for invalid JSON data in tests and the validation function.
- Modified the _validate_coverage_json function to support additional input types.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/data/test_validation.py | Updated tests to reflect broader input support and adjusted exceptions. |
p3analysis/data/_validation.py | Modified input type handling and error messages in the validation function. |
Although many of our early tests used coverage strings loaded from CSV files, we have encountered real use-cases where it is easier to work directly with coverage represented as Python objects. Signed-off-by: John Pennycook <[email protected]>
Previously, the test threw a TypeError because the JSON was provided as an object instead of as a string. Now that providing coverage objects is supported, the test is expected to throw a ValueError: it is valid to pass an object, but the object itself is invalid. Signed-off-by: John Pennycook <[email protected]>
Signed-off-by: John Pennycook <[email protected]>
Anything else is invalid JSON, so we should raise a TypeError. Signed-off-by: John Pennycook <[email protected]>
c6c704e
to
5b407ee
Compare
Co-authored-by: Copilot <[email protected]> Signed-off-by: John Pennycook <[email protected]>
Closed and re-opened to trigger the updated CI checks from #76. |
Related issues
Closes #60.
Proposed changes
test_coverage_json_invalid
to reflect that passing objects is now valid.test_coverage_json_valid
to test JSON objects as well as JSON strings.