diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-11-09 18:47:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-09 18:47:49 (GMT) |
commit | 266328552e922fd9030cd699e10a25f03a67c8ba (patch) | |
tree | 5a210ddb5613acd82d11e112959972ed4d4a7a84 /Lib/test/test_pathlib/test_pathlib.py | |
parent | 0f47a3199c51ba7c49e72b4c645dbf599aa17be4 (diff) | |
download | cpython-266328552e922fd9030cd699e10a25f03a67c8ba.zip cpython-266328552e922fd9030cd699e10a25f03a67c8ba.tar.gz cpython-266328552e922fd9030cd699e10a25f03a67c8ba.tar.bz2 |
pathlib ABCs: tighten up `resolve()` and `absolute()` (#126611)
In `PathBase.resolve()`, raise `UnsupportedOperation` if a non-POSIX path
parser is used (our implementation uses `posixpath._realpath()`, which
produces incorrect results for non-POSIX path flavours.) Also tweak code to
call `self.absolute()` upfront rather than supplying an emulated `getcwd()`
function.
Adjust `PathBase.absolute()` to work somewhat like `resolve()`. If a POSIX
path parser is used, we treat the root directory as the current directory.
This is the simplest useful behaviour for concrete path types without a
current directory cursor.
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib.py')
-rw-r--r-- | Lib/test/test_pathlib/test_pathlib.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index c7104bf..46966b6 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -861,6 +861,28 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest): def test_move_into_empty_name_other_os(self): self.test_move_into_empty_name() + def _check_complex_symlinks(self, link0_target): + super()._check_complex_symlinks(link0_target) + P = self.cls(self.base) + # Resolve relative paths. + old_path = os.getcwd() + os.chdir(self.base) + try: + p = self.cls('link0').resolve() + self.assertEqual(p, P) + self.assertEqualNormCase(str(p), self.base) + p = self.cls('link1').resolve() + self.assertEqual(p, P) + self.assertEqualNormCase(str(p), self.base) + p = self.cls('link2').resolve() + self.assertEqual(p, P) + self.assertEqualNormCase(str(p), self.base) + p = self.cls('link3').resolve() + self.assertEqual(p, P) + self.assertEqualNormCase(str(p), self.base) + finally: + os.chdir(old_path) + def test_resolve_nonexist_relative_issue38671(self): p = self.cls('non', 'exist') |