Permit coverage JSON strings and objects#74
Merged
Pennycook merged 5 commits intoP3HPC:mainfrom May 22, 2025
Merged
Conversation
laserkelvin
approved these changes
May 20, 2025
laserkelvin
left a comment
There was a problem hiding this comment.
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.
Do you want to also type check for dict or list? And throw an exception for anything else
Contributor
Author
Contributor
There was a problem hiding this comment.
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 <john.pennycook@intel.com>
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 <john.pennycook@intel.com>
Signed-off-by: John Pennycook <john.pennycook@intel.com>
Anything else is invalid JSON, so we should raise a TypeError. Signed-off-by: John Pennycook <john.pennycook@intel.com>
c6c704e to
5b407ee
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: John Pennycook <john.pennycook@intel.com>
Merged
Contributor
Author
|
Closed and re-opened to trigger the updated CI checks from #76. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related issues
Closes #60.
Proposed changes
test_coverage_json_invalidto reflect that passing objects is now valid.test_coverage_json_validto test JSON objects as well as JSON strings.