Skip to content

Commit 182263d

Browse files
Fix Windows child process tests string escaping
The child process tests were failing on Windows because of incorrect string escaping in the Python scripts passed to subprocesses. The issues were: 1. Missing f-string prefix on parent script strings containing {repr(...)} 2. Incorrect escaping of newlines (\\\\n instead of \\n) 3. Incorrect quote escaping in nested scripts These fixes ensure that: - File paths are properly interpolated using f-strings - Newlines are correctly escaped as \n in the child scripts - Nested quotes use triple quotes instead of escaped quotes Reported-by: fweinberger
1 parent 5ff9a03 commit 182263d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tests/client/test_stdio.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ async def test_stdio_client_child_process_cleanup():
385385
f.write('parent started\\n')
386386
387387
# Child script that writes continuously
388-
child_script = '''
388+
child_script = f'''
389389
import time
390390
with open({repr(marker_file)}, 'a') as f:
391391
while True:
392-
f.write(f"{{time.time()}}\\\\n")
392+
f.write(f"{{time.time()}}\\n")
393393
f.flush()
394394
time.sleep(0.1)
395395
'''
@@ -485,25 +485,25 @@ async def test_stdio_client_nested_process_tree():
485485
import os
486486
487487
# Child will spawn grandchild and write to child file
488-
child_script = '''import subprocess
488+
child_script = f'''import subprocess
489489
import sys
490490
import time
491491
492492
# Grandchild just writes to file
493-
grandchild_script = \\"\\"\\"import time
493+
grandchild_script = """import time
494494
with open({repr(grandchild_file)}, 'a') as f:
495495
while True:
496-
f.write(f"gc {{time.time()}}\\\\\\\\n")
496+
f.write(f"gc {{time.time()}}\\n")
497497
f.flush()
498-
time.sleep(0.1)\\"\\"\\"
498+
time.sleep(0.1)"""
499499
500500
# Spawn grandchild
501501
subprocess.Popen([sys.executable, '-c', grandchild_script])
502502
503503
# Child writes to its file
504504
with open({repr(child_file)}, 'a') as f:
505505
while True:
506-
f.write(f"c {{time.time()}}\\\\\\\\n")
506+
f.write(f"c {{time.time()}}\\n")
507507
f.flush()
508508
time.sleep(0.1)'''
509509
@@ -513,7 +513,7 @@ async def test_stdio_client_nested_process_tree():
513513
# Parent writes to its file
514514
with open({repr(parent_file)}, 'a') as f:
515515
while True:
516-
f.write(f"p {{time.time()}}\\\\n")
516+
f.write(f"p {{time.time()}}\\n")
517517
f.flush()
518518
time.sleep(0.1)
519519
"""
@@ -588,10 +588,10 @@ async def test_stdio_client_early_parent_exit():
588588
import signal
589589
590590
# Child that continues running
591-
child_script = '''import time
591+
child_script = f'''import time
592592
with open({repr(marker_file)}, 'a') as f:
593593
while True:
594-
f.write(f"child {{time.time()}}\\\\n")
594+
f.write(f"child {{time.time()}}\\n")
595595
f.flush()
596596
time.sleep(0.1)'''
597597

0 commit comments

Comments
 (0)