MCPcopy Index your code
hub / github.com/python/cpython / test_sys_remote_exec

Function test_sys_remote_exec

Lib/test/audit-tests.py:648–675  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

646 raise RuntimeError("Expected sys.audit(9) to fail.")
647
648def test_sys_remote_exec():
649 import tempfile
650
651 pid = os.getpid()
652 event_pid = -1
653 event_script_path = ""
654 remote_event_script_path = ""
655 def hook(event, args):
656 if event not in ["sys.remote_exec", "cpython.remote_debugger_script"]:
657 return
658 print(event, args)
659 match event:
660 case "sys.remote_exec":
661 nonlocal event_pid, event_script_path
662 event_pid = args[0]
663 event_script_path = args[1]
664 case "cpython.remote_debugger_script":
665 nonlocal remote_event_script_path
666 remote_event_script_path = args[0]
667
668 sys.addaudithook(hook)
669 with tempfile.NamedTemporaryFile(mode='w+', delete=True) as tmp_file:
670 tmp_file.write("a = 1+1\n")
671 tmp_file.flush()
672 sys.remote_exec(pid, tmp_file.name)
673 assertEqual(event_pid, pid)
674 assertEqual(event_script_path, tmp_file.name)
675 assertEqual(remote_event_script_path, tmp_file.name)
676
677def test_import_module():
678 import importlib

Callers

nothing calls this directly

Calls 3

assertEqualFunction · 0.85
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…