Skip to content

Commit 659556f

Browse files
committed
use dedent
1 parent 30cb537 commit 659556f

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

Lib/test/test_remote_pdb.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@ def _send_interrupt(self, pid):
349349
'if inst := pdb.Pdb._last_pdb_instance:\n'
350350
' inst.set_trace(sys._getframe(1))\n'
351351
)
352+
self.addCleanup(unlink, interrupt_script)
352353
try:
353354
sys.remote_exec(pid, interrupt_script)
354355
except PermissionError:
355356
self.skipTest("Insufficient permissions to execute code in remote process")
356-
self.addCleanup(unlink, interrupt_script)
357357

358358
def test_connect_and_basic_commands(self):
359359
"""Test connecting to a remote debugger and sending basic commands."""
@@ -453,30 +453,30 @@ def test_breakpoints(self):
453453

454454
def test_keyboard_interrupt(self):
455455
"""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+
""")
480480
self._create_script(script=script)
481481
process, client_file = self._connect_and_get_client_file()
482482

@@ -528,32 +528,32 @@ def test_handle_eof(self):
528528
def test_protocol_version(self):
529529
"""Test that incompatible protocol versions are properly detected."""
530530
# 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+
''')
557557
self._create_script(script=script)
558558
process, client_file = self._connect_and_get_client_file()
559559

0 commit comments

Comments
 (0)