summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-03-07 23:15:05 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-03-07 23:15:05 (GMT)
commite3207fe86b23254e6876b033acff36bdc66de7e0 (patch)
tree735900a217186baea6352c9a2f64393e4cc7440a /Lib
parent8c69ecf95dad39aa55af293da75148a551c0e369 (diff)
downloadcpython-e3207fe86b23254e6876b033acff36bdc66de7e0.zip
cpython-e3207fe86b23254e6876b033acff36bdc66de7e0.tar.gz
cpython-e3207fe86b23254e6876b033acff36bdc66de7e0.tar.bz2
Issue #20876: correctly close temporary file in test.support.fs_is_case_insensitive()
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support/__init__.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 32b5687..d223242 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -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: