mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-10-27 07:52:03 +00:00
style: reformat files with black to fix CI
CI checks were failing because three files were out of formatting compliance with black. Reformatted the following files to pass the `black --check .` step: - `scripts/ai_tui_agent_test.py` - `torch/scripts/test-audit/run_python_static_analysis.py` - `torch/scripts/test-audit/run_python_flaky_check.py` Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
17dfd0ec2c
commit
8489aaf529
3 files changed
+51
-28
No files matched your search
@@ -876,7 +876,10 @@ def main() -> int:
|
|||||||
|
|
||||||
cmd = [args.python_bin, str(src_main), "--no-clipboard"]
|
cmd = [args.python_bin, str(src_main), "--no-clipboard"]
|
||||||
if pty is None:
|
if pty is None:
|
||||||
print("Error: pty module not available (POSIX environment required).", file=sys.stderr)
|
print(
|
||||||
|
"Error: pty module not available (POSIX environment required).",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
master_fd, slave_fd = pty.openpty()
|
master_fd, slave_fd = pty.openpty()
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ TEST_PATTERN = "src/tests"
|
|||||||
RESULTS = {}
|
RESULTS = {}
|
||||||
RUN_DIAGNOSTICS = []
|
RUN_DIAGNOSTICS = []
|
||||||
|
|
||||||
|
|
||||||
def run_tests(run_index):
|
def run_tests(run_index):
|
||||||
"""Run pytest and parse output for pass/fail counts."""
|
"""Run pytest and parse output for pass/fail counts."""
|
||||||
print(f"Run {run_index + 1}/{RUNS}...")
|
print(f"Run {run_index + 1}/{RUNS}...")
|
||||||
@@ -19,11 +20,13 @@ def run_tests(run_index):
|
|||||||
# -q: quiet
|
# -q: quiet
|
||||||
# --no-header --no-summary: minimal output
|
# --no-header --no-summary: minimal output
|
||||||
cmd = [
|
cmd = [
|
||||||
sys.executable, "-m", "pytest",
|
sys.executable,
|
||||||
|
"-m",
|
||||||
|
"pytest",
|
||||||
TEST_PATTERN,
|
TEST_PATTERN,
|
||||||
"-q",
|
"-q",
|
||||||
"--no-header",
|
"--no-header",
|
||||||
"--no-summary"
|
"--no-summary",
|
||||||
]
|
]
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
@@ -33,7 +36,7 @@ def run_tests(run_index):
|
|||||||
cmd,
|
cmd,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
env={"PYTHONPATH": "src"} # Ensure src is in path
|
env={"PYTHONPATH": "src"}, # Ensure src is in path
|
||||||
)
|
)
|
||||||
output = result.stdout
|
output = result.stdout
|
||||||
exit_code = result.returncode
|
exit_code = result.returncode
|
||||||
@@ -45,10 +48,10 @@ def run_tests(run_index):
|
|||||||
|
|
||||||
# Parse output character by character for status
|
# Parse output character by character for status
|
||||||
# . = pass, F = fail, E = error, s = skip, x = xfail, X = xpass
|
# . = pass, F = fail, E = error, s = skip, x = xfail, X = xpass
|
||||||
passed = output.count('.')
|
passed = output.count(".")
|
||||||
failed = output.count('F')
|
failed = output.count("F")
|
||||||
errors = output.count('E')
|
errors = output.count("E")
|
||||||
skipped = output.count('s')
|
skipped = output.count("s")
|
||||||
|
|
||||||
# Store aggregate results (naive mapping, ideally we'd parse node ids)
|
# Store aggregate results (naive mapping, ideally we'd parse node ids)
|
||||||
# Since we can't easily map node IDs without -v or --junitxml, we track totals for flakiness *rates* at suite level first.
|
# Since we can't easily map node IDs without -v or --junitxml, we track totals for flakiness *rates* at suite level first.
|
||||||
@@ -56,26 +59,36 @@ def run_tests(run_index):
|
|||||||
|
|
||||||
junit_path = OUTPUT_DIR / f"flaky-run-{run_index + 1}.xml"
|
junit_path = OUTPUT_DIR / f"flaky-run-{run_index + 1}.xml"
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[sys.executable, "-m", "pytest", TEST_PATTERN, f"--junitxml={junit_path}", "-q"],
|
[
|
||||||
capture_output=True, # We only care about the XML file
|
sys.executable,
|
||||||
env={"PYTHONPATH": "src"}
|
"-m",
|
||||||
|
"pytest",
|
||||||
|
TEST_PATTERN,
|
||||||
|
f"--junitxml={junit_path}",
|
||||||
|
"-q",
|
||||||
|
],
|
||||||
|
capture_output=True, # We only care about the XML file
|
||||||
|
env={"PYTHONPATH": "src"},
|
||||||
|
)
|
||||||
|
|
||||||
|
RUN_DIAGNOSTICS.append(
|
||||||
|
{
|
||||||
|
"run": run_index + 1,
|
||||||
|
"code": exit_code,
|
||||||
|
"duration": duration,
|
||||||
|
"passed": passed,
|
||||||
|
"failed": failed,
|
||||||
|
"errors": errors,
|
||||||
|
"skipped": skipped,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
RUN_DIAGNOSTICS.append({
|
|
||||||
"run": run_index + 1,
|
|
||||||
"code": exit_code,
|
|
||||||
"duration": duration,
|
|
||||||
"passed": passed,
|
|
||||||
"failed": failed,
|
|
||||||
"errors": errors,
|
|
||||||
"skipped": skipped
|
|
||||||
})
|
|
||||||
|
|
||||||
def parse_junit_xmls():
|
def parse_junit_xmls():
|
||||||
"""Parse generated JUnit XML files to detect per-test flakiness."""
|
"""Parse generated JUnit XML files to detect per-test flakiness."""
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
test_stats = {} # "test_id": {pass: 0, fail: 0, error: 0, skip: 0}
|
test_stats = {} # "test_id": {pass: 0, fail: 0, error: 0, skip: 0}
|
||||||
|
|
||||||
for i in range(RUNS):
|
for i in range(RUNS):
|
||||||
xml_path = OUTPUT_DIR / f"flaky-run-{i + 1}.xml"
|
xml_path = OUTPUT_DIR / f"flaky-run-{i + 1}.xml"
|
||||||
@@ -108,6 +121,7 @@ def parse_junit_xmls():
|
|||||||
|
|
||||||
return test_stats
|
return test_stats
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
@@ -129,5 +143,6 @@ def main():
|
|||||||
|
|
||||||
print(f"Flakiness matrix written to {OUTPUT_DIR / 'flakiness-matrix.json'}")
|
print(f"Flakiness matrix written to {OUTPUT_DIR / 'flakiness-matrix.json'}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
@@ -20,29 +20,33 @@ PATTERNS = [
|
|||||||
(r"# todo", "Found '# todo' comment"),
|
(r"# todo", "Found '# todo' comment"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def scan_file(filepath):
|
def scan_file(filepath):
|
||||||
"""Scan a single file for suspicious patterns."""
|
"""Scan a single file for suspicious patterns."""
|
||||||
issues = []
|
issues = []
|
||||||
try:
|
try:
|
||||||
content = filepath.read_text(encoding="utf-8")
|
content = filepath.read_text(encoding="utf-8")
|
||||||
except Exception:
|
except Exception:
|
||||||
return # Skip non-text files
|
return # Skip non-text files
|
||||||
|
|
||||||
for pattern, message in PATTERNS:
|
for pattern, message in PATTERNS:
|
||||||
if re.search(pattern, content):
|
if re.search(pattern, content):
|
||||||
issues.append(message)
|
issues.append(message)
|
||||||
|
|
||||||
# Check for lack of assertions (very naive)
|
# Check for lack of assertions (very naive)
|
||||||
if "test_" in filepath.name and "assert" not in content and "expect" not in content and "raise" not in content:
|
if (
|
||||||
|
"test_" in filepath.name
|
||||||
|
and "assert" not in content
|
||||||
|
and "expect" not in content
|
||||||
|
and "raise" not in content
|
||||||
|
):
|
||||||
# Exclude conftest or helpers
|
# Exclude conftest or helpers
|
||||||
if "conftest" not in filepath.name and "helper" not in filepath.name:
|
if "conftest" not in filepath.name and "helper" not in filepath.name:
|
||||||
issues.append("No obvious assertions found")
|
issues.append("No obvious assertions found")
|
||||||
|
|
||||||
if issues:
|
if issues:
|
||||||
SUSPICIOUS.append({
|
SUSPICIOUS.append({"file": str(filepath), "issues": issues})
|
||||||
"file": str(filepath),
|
|
||||||
"issues": issues
|
|
||||||
})
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -62,5 +66,6 @@ def main():
|
|||||||
print(f"Found {len(SUSPICIOUS)} suspicious files.")
|
print(f"Found {len(SUSPICIOUS)} suspicious files.")
|
||||||
print(f"Report written to {OUTPUT_DIR / 'suspicious-tests.json'}.")
|
print(f"Report written to {OUTPUT_DIR / 'suspicious-tests.json'}.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in new issue
Block a user