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

Method test_issue42384_symlink

Lib/test/test_pdb.py:4506–4528  ·  view source on GitHub ↗

When running `python foo.py` sys.path[0] resolves symlinks. `python -m pdb foo.py` should behave the same

(self)

Source from the content-addressed store, hash-verified

4504
4505 @os_helper.skip_unless_symlink
4506 def test_issue42384_symlink(self):
4507 '''When running `python foo.py` sys.path[0] resolves symlinks. `python -m pdb foo.py` should behave the same'''
4508 script = textwrap.dedent("""
4509 import sys
4510 print('sys.path[0] is', sys.path[0])
4511 """)
4512 commands = 'c\nq'
4513
4514 with os_helper.temp_cwd() as cwd:
4515 cwd = os.path.realpath(cwd)
4516 dir_one = os.path.join(cwd, 'dir_one')
4517 dir_two = os.path.join(cwd, 'dir_two')
4518 expected = f'(Pdb) sys.path[0] is {dir_one}'
4519
4520 os.mkdir(dir_one)
4521 with open(os.path.join(dir_one, 'foo.py'), 'w') as f:
4522 f.write(script)
4523 os.mkdir(dir_two)
4524 os.symlink(os.path.join(dir_one, 'foo.py'), os.path.join(dir_two, 'foo.py'))
4525
4526 stdout, stderr = self._run_pdb([os.path.join('dir_two', 'foo.py')], commands)
4527
4528 self.assertEqual(stdout.split('\n')[2].rstrip('\r'), expected)
4529
4530 def test_safe_path(self):
4531 """ With safe_path set, pdb should not mangle sys.path[0]"""

Callers

nothing calls this directly

Calls 10

_run_pdbMethod · 0.95
openFunction · 0.50
dedentMethod · 0.45
realpathMethod · 0.45
joinMethod · 0.45
mkdirMethod · 0.45
writeMethod · 0.45
assertEqualMethod · 0.45
rstripMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected