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).
This commit is contained in:
Victor Stinner 2011-06-30 23:25:47 +02:00
parent 61600cb0c3
commit bf816223df
17 changed files with 50 additions and 53 deletions

View file

@ -893,7 +893,7 @@ class WriteTest(WriteTestBase):
try:
for name in ("foo", "bar", "baz"):
name = os.path.join(tempdir, name)
open(name, "wb").close()
support.create_empty_file(name)
exclude = os.path.isfile
@ -920,7 +920,7 @@ class WriteTest(WriteTestBase):
try:
for name in ("foo", "bar", "baz"):
name = os.path.join(tempdir, name)
open(name, "wb").close()
support.create_empty_file(name)
def filter(tarinfo):
if os.path.basename(tarinfo.name) == "bar":
@ -959,7 +959,7 @@ class WriteTest(WriteTestBase):
# and compare the stored name with the original.
foo = os.path.join(TEMPDIR, "foo")
if not dir:
open(foo, "w").close()
support.create_empty_file(foo)
else:
os.mkdir(foo)