diff options
author | Philip Jenvey <pjenvey@underboss.org> | 2009-05-28 06:09:08 (GMT) |
---|---|---|
committer | Philip Jenvey <pjenvey@underboss.org> | 2009-05-28 06:09:08 (GMT) |
commit | a27c5bd2bd09da1239f038cccf89cbbba32933ab (patch) | |
tree | 1f5136ab5dfd243fe2d39f4a21b7353f7750f362 /Lib/test/test_univnewlines.py | |
parent | 3d2dc35a2847ce89aee31889253fb52b7c5e26a0 (diff) | |
download | cpython-a27c5bd2bd09da1239f038cccf89cbbba32933ab.zip cpython-a27c5bd2bd09da1239f038cccf89cbbba32933ab.tar.gz cpython-a27c5bd2bd09da1239f038cccf89cbbba32933ab.tar.bz2 |
Merged revisions 72979 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72979 | philip.jenvey | 2009-05-27 22:58:44 -0700 (Wed, 27 May 2009) | 2 lines
explicitly close files
........
Diffstat (limited to 'Lib/test/test_univnewlines.py')
-rw-r--r-- | Lib/test/test_univnewlines.py | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py index 39f5519..183ae75 100644 --- a/Lib/test/test_univnewlines.py +++ b/Lib/test/test_univnewlines.py @@ -37,12 +37,11 @@ class TestGenericUnivNewlines(unittest.TestCase): WRITEMODE = 'wb' def setUp(self): - fp = self.open(support.TESTFN, self.WRITEMODE) data = self.DATA if "b" in self.WRITEMODE: data = data.encode("ascii") - fp.write(data) - fp.close() + with self.open(support.TESTFN, self.WRITEMODE) as fp: + fp.write(data) def tearDown(self): try: @@ -51,35 +50,35 @@ class TestGenericUnivNewlines(unittest.TestCase): pass def test_read(self): - fp = self.open(support.TESTFN, self.READMODE) - data = fp.read() + with self.open(support.TESTFN, self.READMODE) as fp: + data = fp.read() self.assertEqual(data, DATA_LF) self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_readlines(self): - fp = self.open(support.TESTFN, self.READMODE) - data = fp.readlines() + with self.open(support.TESTFN, self.READMODE) as fp: + data = fp.readlines() self.assertEqual(data, DATA_SPLIT) self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_readline(self): - fp = self.open(support.TESTFN, self.READMODE) - data = [] - d = fp.readline() - while d: - data.append(d) + with self.open(support.TESTFN, self.READMODE) as fp: + data = [] d = fp.readline() + while d: + data.append(d) + d = fp.readline() self.assertEqual(data, DATA_SPLIT) self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) def test_seek(self): - fp = self.open(support.TESTFN, self.READMODE) - fp.readline() - pos = fp.tell() - data = fp.readlines() - self.assertEqual(data, DATA_SPLIT[1:]) - fp.seek(pos) - data = fp.readlines() + with self.open(support.TESTFN, self.READMODE) as fp: + fp.readline() + pos = fp.tell() + data = fp.readlines() + self.assertEqual(data, DATA_SPLIT[1:]) + fp.seek(pos) + data = fp.readlines() self.assertEqual(data, DATA_SPLIT[1:]) @@ -96,10 +95,10 @@ class TestCRLFNewlines(TestGenericUnivNewlines): DATA = DATA_CRLF def test_tell(self): - fp = self.open(support.TESTFN, self.READMODE) - self.assertEqual(repr(fp.newlines), repr(None)) - data = fp.readline() - pos = fp.tell() + with self.open(support.TESTFN, self.READMODE) as fp: + self.assertEqual(repr(fp.newlines), repr(None)) + data = fp.readline() + pos = fp.tell() self.assertEqual(repr(fp.newlines), repr(self.NEWLINE)) class TestMixedNewlines(TestGenericUnivNewlines): |