@@ -349,11 +349,11 @@ def _send_interrupt(self, pid):
349
349
'if inst := pdb.Pdb._last_pdb_instance:\n '
350
350
' inst.set_trace(sys._getframe(1))\n '
351
351
)
352
+ self .addCleanup (unlink , interrupt_script )
352
353
try :
353
354
sys .remote_exec (pid , interrupt_script )
354
355
except PermissionError :
355
356
self .skipTest ("Insufficient permissions to execute code in remote process" )
356
- self .addCleanup (unlink , interrupt_script )
357
357
358
358
def test_connect_and_basic_commands (self ):
359
359
"""Test connecting to a remote debugger and sending basic commands."""
@@ -453,30 +453,30 @@ def test_breakpoints(self):
453
453
454
454
def test_keyboard_interrupt (self ):
455
455
"""Test that sending keyboard interrupt breaks into pdb."""
456
- script = f"""
457
- import time
458
- import sys
459
- import pdb
460
- def bar():
461
- frame = sys._getframe() # Get the current frame
462
- pdb._connect(
463
- host='127.0.0.1',
464
- port={ self .port } ,
465
- frame=frame,
466
- commands="",
467
- version=pdb._PdbServer.protocol_version(),
468
- )
469
- print("Connected to debugger")
470
- iterations = 10
471
- while iterations > 0:
472
- print("Iteration", iterations)
473
- time.sleep(1)
474
- iterations -= 1
475
- return 42
476
-
477
- if __name__ == "__main__":
478
- print("Function returned:", bar())
479
- """
456
+ script = textwrap . dedent ( f"""
457
+ import time
458
+ import sys
459
+ import pdb
460
+ def bar():
461
+ frame = sys._getframe() # Get the current frame
462
+ pdb._connect(
463
+ host='127.0.0.1',
464
+ port={ self .port } ,
465
+ frame=frame,
466
+ commands="",
467
+ version=pdb._PdbServer.protocol_version(),
468
+ )
469
+ print("Connected to debugger")
470
+ iterations = 10
471
+ while iterations > 0:
472
+ print("Iteration", iterations)
473
+ time.sleep(1)
474
+ iterations -= 1
475
+ return 42
476
+
477
+ if __name__ == "__main__":
478
+ print("Function returned:", bar())
479
+ """)
480
480
self ._create_script (script = script )
481
481
process , client_file = self ._connect_and_get_client_file ()
482
482
@@ -528,32 +528,32 @@ def test_handle_eof(self):
528
528
def test_protocol_version (self ):
529
529
"""Test that incompatible protocol versions are properly detected."""
530
530
# Create a script using an incompatible protocol version
531
- script = f"""
532
- import sys
533
- import pdb
534
-
535
- def run_test():
536
- frame = sys._getframe()
537
-
538
- # Use a fake version number that's definitely incompatible
539
- fake_version = 0x01010101 # A fake version that doesn't match any real Python version
540
-
541
- # Connect with the wrong version
542
- pdb._connect(
543
- host='127.0.0.1',
544
- port={ self .port } ,
545
- frame=frame,
546
- commands="",
547
- version=fake_version,
548
- )
549
-
550
- # This should print if the debugger detaches correctly
551
- print("Debugger properly detected version mismatch")
552
- return True
553
-
554
- if __name__ == "__main__":
555
- print("Test result:", run_test())
556
- """
531
+ script = textwrap . dedent ( f'''
532
+ import sys
533
+ import pdb
534
+
535
+ def run_test():
536
+ frame = sys._getframe()
537
+
538
+ # Use a fake version number that's definitely incompatible
539
+ fake_version = 0x01010101 # A fake version that doesn't match any real Python version
540
+
541
+ # Connect with the wrong version
542
+ pdb._connect(
543
+ host='127.0.0.1',
544
+ port={ self .port } ,
545
+ frame=frame,
546
+ commands="",
547
+ version=fake_version,
548
+ )
549
+
550
+ # This should print if the debugger detaches correctly
551
+ print("Debugger properly detected version mismatch")
552
+ return True
553
+
554
+ if __name__ == "__main__":
555
+ print("Test result:", run_test())
556
+ ''' )
557
557
self ._create_script (script = script )
558
558
process , client_file = self ._connect_and_get_client_file ()
559
559
0 commit comments