Unverified Kaydet (Commit) c2745d2d authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka Kaydeden (comit) GitHub

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.
üst ac1ee1ba
...@@ -8,6 +8,7 @@ import io ...@@ -8,6 +8,7 @@ import io
import _pyio as pyio import _pyio as pyio
from test.support import TESTFN from test.support import TESTFN
from test import support
from collections import UserList from collections import UserList
class AutoFileTests: class AutoFileTests:
...@@ -19,7 +20,7 @@ class AutoFileTests: ...@@ -19,7 +20,7 @@ class AutoFileTests:
def tearDown(self): def tearDown(self):
if self.f: if self.f:
self.f.close() self.f.close()
os.remove(TESTFN) support.unlink(TESTFN)
def testWeakRefs(self): def testWeakRefs(self):
# verify weak references # verify weak references
...@@ -137,8 +138,12 @@ class PyAutoFileTests(AutoFileTests, unittest.TestCase): ...@@ -137,8 +138,12 @@ class PyAutoFileTests(AutoFileTests, unittest.TestCase):
class OtherFileTests: class OtherFileTests:
def tearDown(self):
support.unlink(TESTFN)
def testModeStrings(self): def testModeStrings(self):
# check invalid mode strings # check invalid mode strings
self.open(TESTFN, 'wb').close()
for mode in ("", "aU", "wU+", "U+", "+U", "rU+"): for mode in ("", "aU", "wU+", "U+", "+U", "rU+"):
try: try:
f = self.open(TESTFN, mode) f = self.open(TESTFN, mode)
...@@ -185,7 +190,6 @@ class OtherFileTests: ...@@ -185,7 +190,6 @@ class OtherFileTests:
# SF bug <http://www.python.org/sf/801631> # SF bug <http://www.python.org/sf/801631>
# "file.truncate fault on windows" # "file.truncate fault on windows"
os.unlink(TESTFN)
f = self.open(TESTFN, 'wb') f = self.open(TESTFN, 'wb')
try: try:
...@@ -209,7 +213,6 @@ class OtherFileTests: ...@@ -209,7 +213,6 @@ class OtherFileTests:
self.fail("File size after ftruncate wrong %d" % size) self.fail("File size after ftruncate wrong %d" % size)
finally: finally:
f.close() f.close()
os.unlink(TESTFN)
def testIteration(self): def testIteration(self):
# Test the complex interaction when mixing file-iteration and the # Test the complex interaction when mixing file-iteration and the
...@@ -230,7 +233,6 @@ class OtherFileTests: ...@@ -230,7 +233,6 @@ class OtherFileTests:
methods = [("readline", ()), ("read", ()), ("readlines", ()), methods = [("readline", ()), ("read", ()), ("readlines", ()),
("readinto", (array("b", b" "*100),))] ("readinto", (array("b", b" "*100),))]
try:
# Prepare the testfile # Prepare the testfile
bag = self.open(TESTFN, "wb") bag = self.open(TESTFN, "wb")
bag.write(filler * nchunks) bag.write(filler * nchunks)
...@@ -309,8 +311,6 @@ class OtherFileTests: ...@@ -309,8 +311,6 @@ class OtherFileTests:
self.fail("read* failed after next() consumed file") self.fail("read* failed after next() consumed file")
finally: finally:
f.close() f.close()
finally:
os.unlink(TESTFN)
class COtherFileTests(OtherFileTests, unittest.TestCase): class COtherFileTests(OtherFileTests, unittest.TestCase):
open = io.open open = io.open
...@@ -319,11 +319,5 @@ class PyOtherFileTests(OtherFileTests, unittest.TestCase): ...@@ -319,11 +319,5 @@ class PyOtherFileTests(OtherFileTests, unittest.TestCase):
open = staticmethod(pyio.open) 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__': if __name__ == '__main__':
unittest.main() unittest.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