Commit 23999158 authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

[2.7] bpo-33751: Fix test_file. (GH-7378) (GH-7445)

testModeStrings and testTruncateOnWindows were depended on
a file leaked in other tests.

Also improve cleaning up after tests.
(cherry picked from commit c2745d2d)
parent 02b4d67a
......@@ -12,7 +12,8 @@ from weakref import proxy
import io
import _pyio as pyio
from test.test_support import TESTFN, run_unittest
from test.support import TESTFN, run_unittest
from test import support
from UserList import UserList
class AutoFileTests(unittest.TestCase):
......@@ -24,7 +25,7 @@ class AutoFileTests(unittest.TestCase):
def tearDown(self):
if self.f:
self.f.close()
os.remove(TESTFN)
support.unlink(TESTFN)
def testWeakRefs(self):
# verify weak references
......@@ -143,8 +144,12 @@ class PyAutoFileTests(AutoFileTests):
class OtherFileTests(unittest.TestCase):
def tearDown(self):
support.unlink(TESTFN)
def testModeStrings(self):
# check invalid mode strings
self.open(TESTFN, 'wb').close()
for mode in ("", "aU", "wU+"):
try:
f = self.open(TESTFN, mode)
......@@ -191,7 +196,6 @@ class OtherFileTests(unittest.TestCase):
# SF bug <http://www.python.org/sf/801631>
# "file.truncate fault on windows"
os.unlink(TESTFN)
f = self.open(TESTFN, 'wb')
try:
......@@ -215,7 +219,6 @@ class OtherFileTests(unittest.TestCase):
self.fail("File size after ftruncate wrong %d" % size)
finally:
f.close()
os.unlink(TESTFN)
def testIteration(self):
# Test the complex interaction when mixing file-iteration and the
......@@ -236,7 +239,6 @@ class OtherFileTests(unittest.TestCase):
methods = [("readline", ()), ("read", ()), ("readlines", ()),
("readinto", (array("b", b" "*100),))]
try:
# Prepare the testfile
bag = self.open(TESTFN, "wb")
bag.write(filler * nchunks)
......@@ -314,8 +316,6 @@ class OtherFileTests(unittest.TestCase):
self.fail("read* failed after next() consumed file")
finally:
f.close()
finally:
os.unlink(TESTFN)
class COtherFileTests(OtherFileTests):
open = io.open
......@@ -325,14 +325,8 @@ class PyOtherFileTests(OtherFileTests):
def test_main():
# Historically, these tests have been sloppy about removing TESTFN.
# So get rid of it no matter what.
try:
run_unittest(CAutoFileTests, PyAutoFileTests,
COtherFileTests, PyOtherFileTests)
finally:
if os.path.exists(TESTFN):
os.unlink(TESTFN)
if __name__ == '__main__':
test_main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment