Skip to content

Commit ff64add

Browse files
authored
bpo-34195: Fix case-sensitive comparison in test_nt_helpers (GH-8448)
* Fix case-sensitive comparison test_nt_helpers assumed that two versions of a Windows path could be compared case-sensitively. This is not the case, and the difference can be triggered (apparently) by running the test on a path somewhere below a Junction.
1 parent ee98e7b commit ff64add

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Lib/test/test_ntpath.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,16 +422,22 @@ def test_ismount(self):
422422
self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$"))
423423
self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$\\"))
424424

425+
def assertEqualCI(self, s1, s2):
426+
"""Assert that two strings are equal ignoring case differences."""
427+
self.assertEqual(s1.lower(), s2.lower())
428+
425429
@unittest.skipUnless(nt, "OS helpers require 'nt' module")
426430
def test_nt_helpers(self):
427431
# Trivial validation that the helpers do not break, and support both
428432
# unicode and bytes (UTF-8) paths
429433

430-
drive, path = ntpath.splitdrive(sys.executable)
431-
drive = drive.rstrip(ntpath.sep) + ntpath.sep
432-
self.assertEqual(drive, nt._getvolumepathname(sys.executable))
433-
self.assertEqual(drive.encode(),
434-
nt._getvolumepathname(sys.executable.encode()))
434+
executable = nt._getfinalpathname(sys.executable)
435+
436+
for path in executable, os.fsencode(executable):
437+
volume_path = nt._getvolumepathname(path)
438+
path_drive = ntpath.splitdrive(path)[0]
439+
volume_path_drive = ntpath.splitdrive(volume_path)[0]
440+
self.assertEqualCI(path_drive, volume_path_drive)
435441

436442
cap, free = nt._getdiskusage(sys.exec_prefix)
437443
self.assertGreater(cap, 0)

0 commit comments

Comments
 (0)