Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe77f4e

Browse files
committed
Issue #19718: Add a case-insensitive FS check to test.support to use
in test_pathlib. Purposefully designed to work from a specified directory in case multiple file systems are used on the system.
1 parent aa40775 commit fe77f4e

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"captured_stdin", "captured_stderr",
7777
# filesystem
7878
"TESTFN", "SAVEDCWD", "unlink", "rmtree", "temp_cwd", "findfile",
79-
"create_empty_file", "can_symlink",
79+
"create_empty_file", "can_symlink", "fs_is_case_insensitive",
8080
# unittest
8181
"is_resource_enabled", "requires", "requires_freebsd_version",
8282
"requires_linux_version", "requires_mac_ver", "check_syntax_error",
@@ -2045,6 +2045,20 @@ def skip_unless_xattr(test):
20452045
return test if ok else unittest.skip(msg)(test)
20462046

20472047

2048+
def fs_is_case_insensitive(directory):
2049+
"""Detects if the file system for the specified directory is case-insensitive."""
2050+
base_fp, base_path = tempfile.mkstemp(dir=directory)
2051+
case_path = base_path.upper()
2052+
if case_path == base_path:
2053+
case_path = base_path.lower()
2054+
try:
2055+
return os.path.samefile(base_path, case_path)
2056+
except FileNotFoundError:
2057+
return False
2058+
finally:
2059+
os.unlink(base_path)
2060+
2061+
20482062
class SuppressCrashReport:
20492063
"""Try to prevent a crash report from popping up.
20502064

Lib/test/test_pathlib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,12 +1623,16 @@ def test_resolve_loop(self):
16231623
def test_glob(self):
16241624
P = self.cls
16251625
p = P(BASE)
1626-
self.assertEqual(set(p.glob("FILEa")), set())
1626+
given = set(p.glob("FILEa"))
1627+
expect = set() if not support.fs_is_case_insensitive(BASE) else given
1628+
self.assertEqual(given, expect)
16271629

16281630
def test_rglob(self):
16291631
P = self.cls
16301632
p = P(BASE, "dirC")
1631-
self.assertEqual(set(p.rglob("FILEd")), set())
1633+
given = set(p.rglob("FILEd"))
1634+
expect = set() if not support.fs_is_case_insensitive(BASE) else given
1635+
self.assertEqual(given, expect)
16321636

16331637

16341638
@only_nt

0 commit comments

Comments
 (0)