Skip to content

Permit coverage JSON strings and objects#74

Merged
Pennycook merged 5 commits intoP3HPC:mainfrom
Pennycook:permissive-coverage-arg
May 22, 2025
Merged

Permit coverage JSON strings and objects#74
Pennycook merged 5 commits intoP3HPC:mainfrom
Pennycook:permissive-coverage-arg

Conversation

@Pennycook
Copy link
Contributor

Related issues

Closes #60.

Proposed changes

  • Relax restrictions on types expected by coverage validation routine to permit JSON objects.
  • Adjust test_coverage_json_invalid to reflect that passing objects is now valid.
  • Adjust test_coverage_json_valid to test JSON objects as well as JSON strings.

@Pennycook Pennycook added the enhancement New feature or request label Nov 15, 2024
@Pennycook Pennycook added this to the 1.0.0 milestone Nov 15, 2024
Copy link

@laserkelvin laserkelvin left a 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

instance = json.loads(json_string)
if isinstance(json_data, str):
instance = json.loads(json_data)
else:

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

Copy link
Contributor Author

@Pennycook Pennycook May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I've made this change in c6c704e, and added some new tests.

EDIT: 5b407ee is the corresponding commit after the rebase.

@Pennycook Pennycook requested a review from Copilot May 21, 2025 09:34
Copy link
Contributor

Copilot AI left a 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.

Pennycook added 4 commits May 21, 2025 10:36
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>
@Pennycook Pennycook force-pushed the permissive-coverage-arg branch from c6c704e to 5b407ee Compare May 21, 2025 09:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: John Pennycook <john.pennycook@intel.com>
@Pennycook Pennycook mentioned this pull request May 21, 2025
@Pennycook Pennycook closed this May 21, 2025
@Pennycook Pennycook reopened this May 21, 2025
@Pennycook
Copy link
Contributor Author

Closed and re-opened to trigger the updated CI checks from #76.

@Pennycook Pennycook merged commit 1a64abc into P3HPC:main May 22, 2025
7 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support coverage strings and objects

3 participants