gh-104803: Implement ntpath.isdevdrive for checking whether a path is on a Windows Dev Drive (GH-104805)

This commit is contained in:
Steve Dower 2023-05-29 10:05:32 +01:00 committed by GitHub
parent e92ac0a741
commit bfd20d257e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 216 additions and 1 deletions

View file

@ -992,6 +992,26 @@ class TestNtpath(NtpathTestCase):
self.assertTrue(os.path.exists is nt._path_exists)
self.assertFalse(inspect.isfunction(os.path.exists))
@unittest.skipIf(os.name != 'nt', "Dev Drives only exist on Win32")
def test_isdevdrive(self):
# Result may be True or False, but shouldn't raise
self.assertIn(ntpath.isdevdrive(os_helper.TESTFN), (True, False))
# ntpath.isdevdrive can handle relative paths
self.assertIn(ntpath.isdevdrive("."), (True, False))
self.assertIn(ntpath.isdevdrive(b"."), (True, False))
# Volume syntax is supported
self.assertIn(ntpath.isdevdrive(os.listvolumes()[0]), (True, False))
# Invalid volume returns False from os.path method
self.assertFalse(ntpath.isdevdrive(r"\\?\Volume{00000000-0000-0000-0000-000000000000}\\"))
# Invalid volume raises from underlying helper
with self.assertRaises(OSError):
nt._path_isdevdrive(r"\\?\Volume{00000000-0000-0000-0000-000000000000}\\")
@unittest.skipIf(os.name == 'nt', "isdevdrive fallback only used off Win32")
def test_isdevdrive_fallback(self):
# Fallback always returns False
self.assertFalse(ntpath.isdevdrive(os_helper.TESTFN))
class NtCommonTest(test_genericpath.CommonTest, unittest.TestCase):
pathmodule = ntpath