diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2015-03-07 23:18:29 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2015-03-07 23:18:29 (GMT) |
commit | adb351fcea72291b606ef03013644fd080dc4f77 (patch) | |
tree | 519c5b437ecb2cebad6255e7695468430c4c2f71 /Lib/test/support | |
parent | 88f64f392c8fe8cb41322c2ea14483fa0c567eaa (diff) | |
parent | e3207fe86b23254e6876b033acff36bdc66de7e0 (diff) | |
download | cpython-adb351fcea72291b606ef03013644fd080dc4f77.zip cpython-adb351fcea72291b606ef03013644fd080dc4f77.tar.gz cpython-adb351fcea72291b606ef03013644fd080dc4f77.tar.bz2 |
Issue #20876: correctly close temporary file in test.support.fs_is_case_insensitive()
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 0ef2e8a..7ef6980 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -2134,16 +2134,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: |