Explorer
/tmp/fix_chdir3.py
← Zurück ↓ Download
#!/usr/bin/env python3
"""Fix ADOPT test: chdir to /tmp BEFORE m.run(q2)."""
p = '/tmp/p2w_test.py'
src = open(p).read()
old = '''b2 = io.StringIO()
with contextlib.redirect_stdout(b2):
    m.run(q2, dry_run=False)'''
new = '''import os as _o
_o.chdir('/tmp')
b2 = io.StringIO()
with contextlib.redirect_stdout(b2):
    m.run(q2, dry_run=False)'''
assert old in src
open(p, 'w').write(src.replace(old, new))
print('chdir added before adopt run')