When running `python foo.py` sys.path[0] resolves symlinks. `python -m pdb foo.py` should behave the same
(self)
| 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]""" |