diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-12-16 18:57:41 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-12-16 18:57:41 (GMT) |
commit | c274fd22edd2471b4f73f5cc690851cfbc716589 (patch) | |
tree | 3dc529eb9aed8034ba7a01dc3544328d6500f8df /Lib/test/test_pathlib.py | |
parent | d2e48ca813a70edc4a28477c150ad8079df584e6 (diff) | |
download | cpython-c274fd22edd2471b4f73f5cc690851cfbc716589.zip cpython-c274fd22edd2471b4f73f5cc690851cfbc716589.tar.gz cpython-c274fd22edd2471b4f73f5cc690851cfbc716589.tar.bz2 |
Issue #19887: Improve the Path.resolve() algorithm to support certain symlink chains.
Original patch by Serhiy.
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rwxr-xr-x | Lib/test/test_pathlib.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index a8d740f..0ad77e0 100755 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1620,6 +1620,59 @@ class _BasePathTest(object): # 'bin' self.assertIs(p.parts[2], q.parts[3]) + def _check_complex_symlinks(self, link0_target): + # Test solving a non-looping chain of symlinks (issue #19887) + P = self.cls(BASE) + self.dirlink(os.path.join('link0', 'link0'), join('link1')) + self.dirlink(os.path.join('link1', 'link1'), join('link2')) + self.dirlink(os.path.join('link2', 'link2'), join('link3')) + self.dirlink(link0_target, join('link0')) + + # Resolve absolute paths + p = (P / 'link0').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + p = (P / 'link1').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + p = (P / 'link2').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + p = (P / 'link3').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + + # Resolve relative paths + old_path = os.getcwd() + os.chdir(BASE) + try: + p = self.cls('link0').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + p = self.cls('link1').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + p = self.cls('link2').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + p = self.cls('link3').resolve() + self.assertEqual(p, P) + self.assertEqual(str(p), BASE) + finally: + os.chdir(old_path) + + @with_symlinks + def test_complex_symlinks_absolute(self): + self._check_complex_symlinks(BASE) + + @with_symlinks + def test_complex_symlinks_relative(self): + self._check_complex_symlinks('.') + + @with_symlinks + def test_complex_symlinks_relative_dot_dot(self): + self._check_complex_symlinks(os.path.join('dirA', '..')) + class PathTest(_BasePathTest, unittest.TestCase): cls = pathlib.Path |