Skip to content
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

JSON report generation from scan results #1929

Merged
merged 15 commits into from
Jun 10, 2024
Merged

JSON report generation from scan results #1929

merged 15 commits into from
Jun 10, 2024

Conversation

bmalezieux
Copy link
Contributor

Description

Related Issue

Type of Change

  • 📚 Examples / docs / tutorials / dependencies update
  • 🔧 Bug fix (non-breaking change which fixes an issue)
  • 🥂 Improvement (non-breaking change which improves an existing feature)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 🔐 Security fix

Checklist

  • I've read the CODE_OF_CONDUCT.md document.
  • I've read the CONTRIBUTING.md guide.
  • I've written tests for all new methods and classes that I created.
  • I've written the docstring in Google format for all the methods and classes that I used.
  • I've updated the pdm.lock running pdm update-lock (only applicable when pyproject.toml has been
    modified)

@mattbit
Copy link
Member

mattbit commented May 21, 2024

@bmalezieux you might need something different, but for reference the AVID integration could be helpful (it also generates JSON reports from the scan, following the AVID schema).

@bmalezieux bmalezieux marked this pull request as ready for review June 3, 2024 15:35
Copy link
Member

@rabah-khalek rabah-khalek left a comment

Choose a reason for hiding this comment

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

since <detector>.run() produces a list of issues, which then you're looping over to jsonify, I would suggest to implicitly infer the detector names inside the run, and add this info to the issue's meta, which then you can group based on in to_json of ScanReport. detectors_names shouldn't be an input to the report, as we already have this info somewhere.

def to_json(self, filename=None):
results = {}
for suite_result in self.results:
results[suite_result.test_name] = "Passed" if suite_result.result.passed else "Failed"
Copy link
Member

Choose a reason for hiding this comment

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

can we add all the meta data that is available / could be useful?

  • metric value
  • model name
  • dataset(s) name(s)

with open(filename, "w") as json_file:
json.dump(results, json_file, indent=4)
else:
return results
Copy link
Member

Choose a reason for hiding this comment

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

I would perhaps return the json representation instead of the dict here

return json.dumps(results, indent=4)

Copy link
Member

Choose a reason for hiding this comment

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

Or let's simply remove this else, and always return the results

@@ -574,6 +585,7 @@ def run(self, verbose: bool = True, **suite_run_args):

if isinstance(result, bool):
result = TestResult(passed=result)
print("TEMP: ", test_partial.test_id, result.passed)
Copy link
Member

Choose a reason for hiding this comment

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

to be removed

@@ -18,7 +19,7 @@


class ScanReport:
def __init__(self, issues, model=None, dataset=None, as_html: bool = True):
def __init__(self, issues, model=None, dataset=None, detectors_names=None, as_html: bool = True):
Copy link
Member

Choose a reason for hiding this comment

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

i thought the idea was to remove this argument. Do we really need to know which detector didn't produce issues?

@@ -51,3 +51,25 @@ def test_scan_report_exports_to_markdown():
assert dest.exists()
assert dest.is_file()
assert dest.read_text() == markdown


def test_scan_report_to_json():
Copy link
Member

Choose a reason for hiding this comment

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

let's add a test where you pass the detector-names list to the scanreport, and check if the detector is in the json file

@rabah-khalek rabah-khalek self-requested a review June 10, 2024 12:40
Copy link

sonarcloud bot commented Jun 10, 2024

Please retry analysis of this Pull-Request directly on SonarCloud

@rabah-khalek rabah-khalek merged commit 5987d27 into main Jun 10, 2024
15 of 16 checks passed
@rabah-khalek rabah-khalek deleted the json-report branch June 10, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants