summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-05-29 12:36:08 (GMT)
committerGitHub <noreply@github.com>2023-05-29 12:36:08 (GMT)
commit635ce29257a7f7272af009d3c08379522317d89b (patch)
treee94651f74c58ee00798cd3874733f9e93ad529d0 /Lib
parent5dc6b18cb0c83faab556b46bdcf96ce21880fa91 (diff)
downloadcpython-635ce29257a7f7272af009d3c08379522317d89b.zip
cpython-635ce29257a7f7272af009d3c08379522317d89b.tar.gz
cpython-635ce29257a7f7272af009d3c08379522317d89b.tar.bz2
gh-104803: Implement ntpath.isdevdrive for checking whether a path is on a Windows Dev Drive (GH-104805)
(cherry picked from commit bfd20d257e4ad16a25f4bac0ea4dbb719cdf6bc7) Co-authored-by: Steve Dower <steve.dower@python.org>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ntpath.py16
-rw-r--r--Lib/test/test_ntpath.py20
2 files changed, 36 insertions, 0 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 0f3674f..dadcdc0 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -867,3 +867,19 @@ try:
except ImportError:
# Use genericpath.* as imported above
pass
+
+
+try:
+ from nt import _path_isdevdrive
+except ImportError:
+ def isdevdrive(path):
+ """Determines whether the specified path is on a Windows Dev Drive."""
+ # Never a Dev Drive
+ return False
+else:
+ def isdevdrive(path):
+ """Determines whether the specified path is on a Windows Dev Drive."""
+ try:
+ return _path_isdevdrive(abspath(path))
+ except OSError:
+ return False
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 0e57c16..538d758 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -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