[Python-checkins] cpython: Issue #19718: Add a case-insensitive FS check to test.support to use
brett.cannon
python-checkins at python.org
Fri Nov 22 22:14:24 CET 2013
http://hg.python.org/cpython/rev/cd09766bb18f
changeset: 87374:cd09766bb18f
parent: 87364:db6ae01a5f7f
user: Brett Cannon <brett at python.org>
date: Fri Nov 22 16:14:10 2013 -0500
summary:
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.
files:
Lib/test/support/__init__.py | 16 +++++++++++++++-
Lib/test/test_pathlib.py | 8 ++++++--
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -76,7 +76,7 @@
"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 @@
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.
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1623,12 +1623,16 @@
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
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list