]> granicus.if.org Git - python/commitdiff
Issue #20876: correctly close temporary file in test.support.fs_is_case_insensitive()
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 7 Mar 2015 23:15:05 +0000 (00:15 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 7 Mar 2015 23:15:05 +0000 (00:15 +0100)
Lib/test/support/__init__.py

index 32b56873622156362ac508aada66e1325b0cbdde..d223242a20859f697b385fdb2c63635fddd0eb16 100644 (file)
@@ -2133,16 +2133,15 @@ def skip_unless_xattr(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)
+    with tempfile.NamedTemporaryFile(dir=directory) as base:
+        base_path = base.name
+        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
 
 
 class SuppressCrashReport: