diff options
author | Brett Cannon <brett@python.org> | 2013-11-22 21:14:10 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-11-22 21:14:10 (GMT) |
commit | fe77f4ebb554bf40b5c1810aeddc2c240aaef431 (patch) | |
tree | ed1f0b15beb7ca3f9ffdbd0792538bb35fb2c7b6 /Lib/test/support | |
parent | aa407758176affde0c81301e3c8856dd73e6b1c3 (diff) | |
download | cpython-fe77f4ebb554bf40b5c1810aeddc2c240aaef431.zip cpython-fe77f4ebb554bf40b5c1810aeddc2c240aaef431.tar.gz cpython-fe77f4ebb554bf40b5c1810aeddc2c240aaef431.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index b6a430e..87c039a 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -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. |