gh-102519: Add os.listdrives, os.listvolumes and os.listmounts on Win… · python/cpython@cafd311

@@ -2648,6 +2648,49 @@ def test_listdir_extended_path(self):

26482648

[os.fsencode(path) for path in self.created_paths])

26492649265026502651+

@unittest.skipUnless(os.name == "nt", "NT specific tests")

2652+

class Win32ListdriveTests(unittest.TestCase):

2653+

"""Test listdrive, listmounts and listvolume on Windows."""

2654+2655+

def setUp(self):

2656+

# Get drives and volumes from fsutil

2657+

out = subprocess.check_output(

2658+

["fsutil.exe", "volume", "list"],

2659+

cwd=os.path.join(os.getenv("SystemRoot", "\\Windows"), "System32"),

2660+

encoding="mbcs",

2661+

errors="ignore",

2662+

)

2663+

lines = out.splitlines()

2664+

self.known_volumes = {l for l in lines if l.startswith('\\\\?\\')}

2665+

self.known_drives = {l for l in lines if l[1:] == ':\\'}

2666+

self.known_mounts = {l for l in lines if l[1:3] == ':\\'}

2667+2668+

def test_listdrives(self):

2669+

drives = os.listdrives()

2670+

self.assertIsInstance(drives, list)

2671+

self.assertSetEqual(

2672+

self.known_drives,

2673+

self.known_drives & set(drives),

2674+

)

2675+2676+

def test_listvolumes(self):

2677+

volumes = os.listvolumes()

2678+

self.assertIsInstance(volumes, list)

2679+

self.assertSetEqual(

2680+

self.known_volumes,

2681+

self.known_volumes & set(volumes),

2682+

)

2683+2684+

def test_listmounts(self):

2685+

for volume in os.listvolumes():

2686+

mounts = os.listmounts(volume)

2687+

self.assertIsInstance(mounts, list)

2688+

self.assertSetEqual(

2689+

set(mounts),

2690+

self.known_mounts & set(mounts),

2691+

)

2692+2693+26512694

@unittest.skipUnless(hasattr(os, 'readlink'), 'needs os.readlink()')

26522695

class ReadlinkTests(unittest.TestCase):

26532696

filelink = 'readlinktest'