mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-33751: Fix test_file. (GH-7378)
testModeStrings and testTruncateOnWindows were depended on a file leaked in other tests. Also improve cleaning up after tests.
This commit is contained in:
parent
ac1ee1bada
commit
c2745d2d05
1 changed files with 79 additions and 85 deletions
|
@ -8,6 +8,7 @@ import io
|
|||
import _pyio as pyio
|
||||
|
||||
from test.support import TESTFN
|
||||
from test import support
|
||||
from collections import UserList
|
||||
|
||||
class AutoFileTests:
|
||||
|
@ -19,7 +20,7 @@ class AutoFileTests:
|
|||
def tearDown(self):
|
||||
if self.f:
|
||||
self.f.close()
|
||||
os.remove(TESTFN)
|
||||
support.unlink(TESTFN)
|
||||
|
||||
def testWeakRefs(self):
|
||||
# verify weak references
|
||||
|
@ -137,8 +138,12 @@ class PyAutoFileTests(AutoFileTests, unittest.TestCase):
|
|||
|
||||
class OtherFileTests:
|
||||
|
||||
def tearDown(self):
|
||||
support.unlink(TESTFN)
|
||||
|
||||
def testModeStrings(self):
|
||||
# check invalid mode strings
|
||||
self.open(TESTFN, 'wb').close()
|
||||
for mode in ("", "aU", "wU+", "U+", "+U", "rU+"):
|
||||
try:
|
||||
f = self.open(TESTFN, mode)
|
||||
|
@ -185,7 +190,6 @@ class OtherFileTests:
|
|||
# SF bug <http://www.python.org/sf/801631>
|
||||
# "file.truncate fault on windows"
|
||||
|
||||
os.unlink(TESTFN)
|
||||
f = self.open(TESTFN, 'wb')
|
||||
|
||||
try:
|
||||
|
@ -209,7 +213,6 @@ class OtherFileTests:
|
|||
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
|
||||
|
@ -230,7 +233,6 @@ class OtherFileTests:
|
|||
methods = [("readline", ()), ("read", ()), ("readlines", ()),
|
||||
("readinto", (array("b", b" "*100),))]
|
||||
|
||||
try:
|
||||
# Prepare the testfile
|
||||
bag = self.open(TESTFN, "wb")
|
||||
bag.write(filler * nchunks)
|
||||
|
@ -309,8 +311,6 @@ class OtherFileTests:
|
|||
self.fail("read* failed after next() consumed file")
|
||||
finally:
|
||||
f.close()
|
||||
finally:
|
||||
os.unlink(TESTFN)
|
||||
|
||||
class COtherFileTests(OtherFileTests, unittest.TestCase):
|
||||
open = io.open
|
||||
|
@ -319,11 +319,5 @@ class PyOtherFileTests(OtherFileTests, unittest.TestCase):
|
|||
open = staticmethod(pyio.open)
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
# Historically, these tests have been sloppy about removing TESTFN.
|
||||
# So get rid of it no matter what.
|
||||
if os.path.exists(TESTFN):
|
||||
os.unlink(TESTFN)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue