diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:14:36 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-14 22:14:36 (GMT) |
commit | ea5d827b729e425751428153318ecc348cc0be50 (patch) | |
tree | 1997afdc83eb0dca7c00c11a71419579e94b871a /Lib/test/test_pipes.py | |
parent | 3d400b7a58a9f6e338048593ae19ab3cc92a8cd3 (diff) | |
download | cpython-ea5d827b729e425751428153318ecc348cc0be50.zip cpython-ea5d827b729e425751428153318ecc348cc0be50.tar.gz cpython-ea5d827b729e425751428153318ecc348cc0be50.tar.bz2 |
Merged revisions 85503 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85503 | antoine.pitrou | 2010-10-15 00:11:44 +0200 (ven., 15 oct. 2010) | 2 lines
More proper closing of files
........
Diffstat (limited to 'Lib/test/test_pipes.py')
-rw-r--r-- | Lib/test/test_pipes.py | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/Lib/test/test_pipes.py b/Lib/test/test_pipes.py index 9c7e8e1..b816a3b 100644 --- a/Lib/test/test_pipes.py +++ b/Lib/test/test_pipes.py @@ -23,17 +23,21 @@ class SimplePipeTests(unittest.TestCase): f = t.open(TESTFN, 'w') f.write('hello world #1') f.close() - self.assertEqual(open(TESTFN).read(), 'HELLO WORLD #1') + with open(TESTFN) as f: + self.assertEqual(f.read(), 'HELLO WORLD #1') def testSimplePipe2(self): - open(TESTFN, 'w').write('hello world #2') + with open(TESTFN, 'w') as f: + f.write('hello world #2') t = pipes.Template() t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT) t.copy(TESTFN, TESTFN2) - self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2') + with open(TESTFN2) as f: + self.assertEqual(f.read(), 'HELLO WORLD #2') def testSimplePipe3(self): - open(TESTFN, 'w').write('hello world #2') + with open(TESTFN, 'w') as f: + f.write('hello world #2') t = pipes.Template() t.append(s_command + ' < $IN', pipes.FILEIN_STDOUT) self.assertEqual(t.open(TESTFN, 'r').read(), 'HELLO WORLD #2') @@ -41,16 +45,20 @@ class SimplePipeTests(unittest.TestCase): def testEmptyPipeline1(self): # copy through empty pipe d = 'empty pipeline test COPY' - open(TESTFN, 'w').write(d) - open(TESTFN2, 'w').write('') + with open(TESTFN, 'w') as f: + f.write(d) + with open(TESTFN2, 'w') as f: + f.write('') t=pipes.Template() t.copy(TESTFN, TESTFN2) - self.assertEqual(open(TESTFN2).read(), d) + with open(TESTFN2) as f: + self.assertEqual(f.read(), d) def testEmptyPipeline2(self): # read through empty pipe d = 'empty pipeline test READ' - open(TESTFN, 'w').write(d) + with open(TESTFN, 'w') as f: + f.write(d) t=pipes.Template() self.assertEqual(t.open(TESTFN, 'r').read(), d) @@ -58,8 +66,10 @@ class SimplePipeTests(unittest.TestCase): # write through empty pipe d = 'empty pipeline test WRITE' t = pipes.Template() - t.open(TESTFN, 'w').write(d) - self.assertEqual(open(TESTFN).read(), d) + with t.open(TESTFN, 'w') as f: + f.write(d) + with open(TESTFN) as f: + self.assertEqual(f.read(), d) def testQuoting(self): safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./' |