test: add prejudge test scripts.#17
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a standalone batch script to run the prejudge analysis across CVE commits listed in a CSV and write results back out to a new CSV, supporting manual/operational validation of src/prejudge behavior.
Changes:
- Introduces
test/test_prejudge.pyCLI script to read an input CSV, runPrejudgeController.analyze_and_report()per commit, and write aPrejudge_Resultcolumn. - Adds basic input file / directory existence checks and prints progress/results to stdout.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Capture the output from analyze_and_report | ||
| from io import StringIO | ||
| import sys | ||
|
|
There was a problem hiding this comment.
StringIO (and even sys) are imported inside the per-row loop. Since these imports are constant, move them to module scope (or at least outside the loop) to reduce noise and avoid repeated work; using contextlib.redirect_stdout also simplifies this block.
| from pathlib import Path | ||
|
|
||
| # Add src directory to path to import prejudge module | ||
| sys.path.insert(0, str(Path(__file__).parent.parent / "src" / "prejudge")) |
There was a problem hiding this comment.
The sys.path tweak doesn’t match the comment: the code inserts .../src/prejudge (not .../src). Either update the comment, or (preferably) add .../src and import PrejudgeController via the package (and ensure PrejudgeController’s internal imports work in that mode).
| sys.path.insert(0, str(Path(__file__).parent.parent / "src" / "prejudge")) | |
| sys.path.insert(0, str(Path(__file__).parent.parent / "src")) |
| for row in reader: | ||
| cve_id = row['CVE-ID'] | ||
| commit_id = row['Mainline_Commit'] | ||
| status = row['Status'] |
There was a problem hiding this comment.
status = row['Status'] is assigned but never used. This can be removed, or used in the output (e.g., to filter rows) to avoid dead code and keep the script easier to maintain.
| status = row['Status'] |
| # Capture stdout | ||
| old_stdout = sys.stdout | ||
| sys.stdout = captured_output = StringIO() | ||
|
|
||
| controller.analyze_and_report(commit_id) | ||
|
|
||
| # Restore stdout | ||
| sys.stdout = old_stdout | ||
| prejudge_result = captured_output.getvalue().strip() | ||
|
|
||
| except Exception as e: | ||
| prejudge_result = f"Error: {str(e)}" | ||
| print(f" Error: {e}") | ||
|
|
There was a problem hiding this comment.
If controller.analyze_and_report() raises, sys.stdout is never restored (because restoration only happens on the success path). This can leave the rest of the script writing into the StringIO buffer. Use a try/finally (or contextlib.redirect_stdout) so stdout is always restored even on exceptions.
No description provided.