mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
check_compute_journal_overlay: catch executable launch OSError in main
This commit is contained in:
@ -121,7 +121,7 @@ def main(argv=None) -> int:
|
||||
try:
|
||||
with tempfile.TemporaryDirectory(prefix="leonida-authored-journal-") as tmp:
|
||||
return run(exe, Path(tmp), args.device, args.require_hit)
|
||||
except (RuntimeError, subprocess.TimeoutExpired) as exc:
|
||||
except (RuntimeError, subprocess.TimeoutExpired, OSError) as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
@ -141,5 +141,31 @@ class CheckComputeJournalOverlayTests(unittest.TestCase):
|
||||
self.assertNotIn("Traceback", err.getvalue())
|
||||
|
||||
|
||||
def test_executable_launch_oserror_reports_cli_error(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
exe = Path(tmp) / "d3d12_compute_journal_test.exe"
|
||||
exe.write_bytes(b"") # real 0-byte exe triggers WinError 193 on Windows
|
||||
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with (
|
||||
mock.patch.object(cjo.subprocess, "run", side_effect=OSError("bad binary")),
|
||||
contextlib.redirect_stdout(out),
|
||||
contextlib.redirect_stderr(err),
|
||||
):
|
||||
rc = cjo.main([str(exe)])
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertEqual(out.getvalue(), "")
|
||||
self.assertIn("ERROR:", err.getvalue())
|
||||
self.assertNotIn("Traceback", err.getvalue())
|
||||
|
||||
if os.name == "nt":
|
||||
out_nt, err_nt = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out_nt), contextlib.redirect_stderr(err_nt):
|
||||
rc_nt = cjo.main([str(exe)])
|
||||
self.assertEqual(rc_nt, 1)
|
||||
self.assertIn("ERROR:", err_nt.getvalue())
|
||||
self.assertNotIn("Traceback", err_nt.getvalue())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user