Issue #12451: Add support.create_empty_file()
We don't need to create a temporary buffered binary or text file object just to
create an empty file.
Replace also os.fdopen(handle).close() by os.close(handle).
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 839f742..ad31f47 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -107,8 +107,7 @@
self.errorState = 0
os.mkdir(TESTFN)
self.childpath = os.path.join(TESTFN, 'a')
- f = open(self.childpath, 'w')
- f.close()
+ support.create_empty_file(self.childpath)
old_dir_mode = os.stat(TESTFN).st_mode
old_child_mode = os.stat(self.childpath).st_mode
# Make unwritable.
@@ -156,7 +155,7 @@
def test_rmtree_dont_delete_file(self):
# When called on a file instead of a directory, don't delete it.
handle, path = tempfile.mkstemp()
- os.fdopen(handle).close()
+ os.close(handle)
self.assertRaises(OSError, shutil.rmtree, path)
os.remove(path)