summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-10-31 01:30:11 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-10-31 01:30:11 (GMT)
commitebe5d8ae3b43f03a48aa02eb11862d234678a01f (patch)
tree07ed626bb058471fda14320da36a62e7b86f87f5 /Lib
parentd8fc2e1aeb3bbd3f08cdb2ea47c2122ca5f99800 (diff)
downloadcpython-ebe5d8ae3b43f03a48aa02eb11862d234678a01f.zip
cpython-ebe5d8ae3b43f03a48aa02eb11862d234678a01f.tar.gz
cpython-ebe5d8ae3b43f03a48aa02eb11862d234678a01f.tar.bz2
patch up leaking fds
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_io.py43
1 files changed, 21 insertions, 22 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 1ea57ac..04b3912 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -555,12 +555,13 @@ class IOTest(unittest.TestCase):
def test_garbage_collection(self):
# FileIO objects are collected, and collecting them flushes
# all data to disk.
- f = self.FileIO(support.TESTFN, "wb")
- f.write(b"abcxxx")
- f.f = f
- wr = weakref.ref(f)
- del f
- support.gc_collect()
+ with support.check_warnings(('', ResourceWarning)):
+ f = self.FileIO(support.TESTFN, "wb")
+ f.write(b"abcxxx")
+ f.f = f
+ wr = weakref.ref(f)
+ del f
+ support.gc_collect()
self.assertTrue(wr() is None, wr)
with self.open(support.TESTFN, "rb") as f:
self.assertEqual(f.read(), b"abcxxx")
@@ -1984,26 +1985,24 @@ class TextIOWrapperTest(unittest.TestCase):
u_suffix = "\u8888\n"
suffix = bytes(u_suffix.encode("utf-8"))
line = prefix + suffix
- f = self.open(support.TESTFN, "wb")
- f.write(line*2)
- f.close()
- f = self.open(support.TESTFN, "r", encoding="utf-8")
- s = f.read(prefix_size)
- self.assertEquals(s, str(prefix, "ascii"))
- self.assertEquals(f.tell(), prefix_size)
- self.assertEquals(f.readline(), u_suffix)
+ with self.open(support.TESTFN, "wb") as f:
+ f.write(line*2)
+ with self.open(support.TESTFN, "r", encoding="utf-8") as f:
+ s = f.read(prefix_size)
+ self.assertEquals(s, str(prefix, "ascii"))
+ self.assertEquals(f.tell(), prefix_size)
+ self.assertEquals(f.readline(), u_suffix)
def test_seeking_too(self):
# Regression test for a specific bug
data = b'\xe0\xbf\xbf\n'
- f = self.open(support.TESTFN, "wb")
- f.write(data)
- f.close()
- f = self.open(support.TESTFN, "r", encoding="utf-8")
- f._CHUNK_SIZE # Just test that it exists
- f._CHUNK_SIZE = 2
- f.readline()
- f.tell()
+ with self.open(support.TESTFN, "wb") as f:
+ f.write(data)
+ with self.open(support.TESTFN, "r", encoding="utf-8") as f:
+ f._CHUNK_SIZE # Just test that it exists
+ f._CHUNK_SIZE = 2
+ f.readline()
+ f.tell()
def test_seek_and_tell(self):
#Test seek/tell using the StatefulIncrementalDecoder.