mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-100809: Fix handling of drive-relative paths in pathlib.Path.absolute() (GH-100812)
Resolving the drive independently uses the OS API, which ensures it starts from the current directory on that drive.
This commit is contained in:
parent
d401b20630
commit
072011b3c3
4 changed files with 64 additions and 1 deletions
|
@ -2973,6 +2973,26 @@ class WindowsPathTest(_BasePathTest, unittest.TestCase):
|
|||
self.assertEqual(str(P('a', 'b', 'c').absolute()),
|
||||
os.path.join(share, 'a', 'b', 'c'))
|
||||
|
||||
drive = os.path.splitdrive(BASE)[0]
|
||||
with os_helper.change_cwd(BASE):
|
||||
# Relative path with root
|
||||
self.assertEqual(str(P('\\').absolute()), drive + '\\')
|
||||
self.assertEqual(str(P('\\foo').absolute()), drive + '\\foo')
|
||||
|
||||
# Relative path on current drive
|
||||
self.assertEqual(str(P(drive).absolute()), BASE)
|
||||
self.assertEqual(str(P(drive + 'foo').absolute()), os.path.join(BASE, 'foo'))
|
||||
|
||||
with os_helper.subst_drive(BASE) as other_drive:
|
||||
# Set the working directory on the substitute drive
|
||||
saved_cwd = os.getcwd()
|
||||
other_cwd = f'{other_drive}\\dirA'
|
||||
os.chdir(other_cwd)
|
||||
os.chdir(saved_cwd)
|
||||
|
||||
# Relative path on another drive
|
||||
self.assertEqual(str(P(other_drive).absolute()), other_cwd)
|
||||
self.assertEqual(str(P(other_drive + 'foo').absolute()), other_cwd + '\\foo')
|
||||
|
||||
def test_glob(self):
|
||||
P = self.cls
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue