]> granicus.if.org Git - python/commitdiff
Issue #19718: Add a case-insensitive FS check to test.support to use
authorBrett Cannon <brett@python.org>
Fri, 22 Nov 2013 21:14:10 +0000 (16:14 -0500)
committerBrett Cannon <brett@python.org>
Fri, 22 Nov 2013 21:14:10 +0000 (16:14 -0500)
in test_pathlib.

Purposefully designed to work from a specified directory in case
multiple file systems are used on the system.

Lib/test/support/__init__.py
Lib/test/test_pathlib.py

index b6a430e491b7b92a16189a1f6c5a2d6f56b6d691..87c039aa0237f299ea664ed08d5e9a31ceafb8d9 100644 (file)
@@ -76,7 +76,7 @@ __all__ = [
     "captured_stdin", "captured_stderr",
     # filesystem
     "TESTFN", "SAVEDCWD", "unlink", "rmtree", "temp_cwd", "findfile",
-    "create_empty_file", "can_symlink",
+    "create_empty_file", "can_symlink", "fs_is_case_insensitive",
     # unittest
     "is_resource_enabled", "requires", "requires_freebsd_version",
     "requires_linux_version", "requires_mac_ver", "check_syntax_error",
@@ -2045,6 +2045,20 @@ def skip_unless_xattr(test):
     return test if ok else unittest.skip(msg)(test)
 
 
+def fs_is_case_insensitive(directory):
+    """Detects if the file system for the specified directory is case-insensitive."""
+    base_fp, base_path = tempfile.mkstemp(dir=directory)
+    case_path = base_path.upper()
+    if case_path == base_path:
+        case_path = base_path.lower()
+    try:
+        return os.path.samefile(base_path, case_path)
+    except FileNotFoundError:
+        return False
+    finally:
+        os.unlink(base_path)
+
+
 class SuppressCrashReport:
     """Try to prevent a crash report from popping up.
 
index e23e5a7de04c0ef66ddfada89102b60dfd237fd8..751764fbbee0dd8b2d8283ff69e3dae13232cc16 100755 (executable)
@@ -1623,12 +1623,16 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
     def test_glob(self):
         P = self.cls
         p = P(BASE)
-        self.assertEqual(set(p.glob("FILEa")), set())
+        given = set(p.glob("FILEa"))
+        expect = set() if not support.fs_is_case_insensitive(BASE) else given
+        self.assertEqual(given, expect)
 
     def test_rglob(self):
         P = self.cls
         p = P(BASE, "dirC")
-        self.assertEqual(set(p.rglob("FILEd")), set())
+        given = set(p.rglob("FILEd"))
+        expect = set() if not support.fs_is_case_insensitive(BASE) else given
+        self.assertEqual(given, expect)
 
 
 @only_nt