Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modelscan/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def generate(
print(f"\n[blue]--- {issue_keys} ---")
for issue in issues_by_severity[issue_keys]:
issue.print()
elif scan.skipped:
# Nothing was scanned successfully, so "no issues" would be misleading.
print(
"\n[yellow] No issues found in the scanned files, but "
f"{len(scan.skipped)} file(s) were skipped and not scanned."
)
else:
print("\n[green] No issues found! πŸŽ‰")

Expand Down
36 changes: 36 additions & 0 deletions tests/test_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Tests for the modelscan console report.
from typing import Any, Dict, List

from modelscan.reports import ConsoleReport


class _Issues:
def __init__(self) -> None:
self.all_issues: List[Any] = []

def group_by_severity(self) -> Dict[str, Any]:
return {}


class _Scan:
"""Minimal stand-in for ModelScan: no issues, no errors, N skipped files."""

def __init__(self, skipped: List[str]) -> None:
self.issues = _Issues()
self.errors: List[Any] = []
self.skipped = skipped


def test_console_report_does_not_claim_success_when_files_are_skipped(capsys: Any) -> None:
ConsoleReport.generate(_Scan(["model.bin"]), settings={"show_skipped": False})

output = capsys.readouterr().out
assert "No issues found!" not in output
assert "No issues found in the scanned files" in output
assert "1 file(s) were skipped" in output


def test_console_report_reports_success_when_nothing_is_skipped(capsys: Any) -> None:
ConsoleReport.generate(_Scan([]), settings={"show_skipped": False})

assert "No issues found!" in capsys.readouterr().out