mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
"""Check request comparison with synthetic saved report JSON."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
SCRIPT = Path(__file__).resolve().parents[2] / "tools" / "compare_software_controls.py"
|
|
|
|
|
|
class EmptyControlsTests(unittest.TestCase):
|
|
def compare(self, records):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
original, rust, output = [
|
|
root / name for name in ("original.json", "rust.json", "output.json")
|
|
]
|
|
for path in (original, rust):
|
|
path.write_text(json.dumps({"records": records}))
|
|
output.write_text("previous report\n")
|
|
result = subprocess.run([
|
|
sys.executable, str(SCRIPT), "--original", str(original),
|
|
"--rust", str(rust), "--out", str(output),
|
|
], capture_output=True, text=True)
|
|
return result, output.read_text()
|
|
|
|
def test_empty_captures_do_not_replace_an_existing_report(self):
|
|
result, output = self.compare([])
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("No records to compare", result.stderr)
|
|
self.assertEqual(output, "previous report\n")
|
|
|
|
def test_a_matching_nonempty_capture_still_passes(self):
|
|
result, output = self.compare([{
|
|
"request": "0x29", "label": "fixture", "input_top": "00" * 12,
|
|
"linux_errno": 0, "status": 0, "response": "00" * 12,
|
|
}])
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
report = json.loads(output)
|
|
self.assertTrue(report["passed"])
|
|
self.assertEqual(report["case_count"], 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|