summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pipes.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-14 22:22:30 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-14 22:22:30 (GMT)
commit99d848bd4ba7bc0df689709f3854d67c6d82a757 (patch)
treed02592b257cb7411854f5f49e904b054af391a90 /Lib/test/test_pipes.py
parent80800d35713912eb4b9486033c1ce86bce263728 (diff)
downloadcpython-99d848bd4ba7bc0df689709f3854d67c6d82a757.zip
cpython-99d848bd4ba7bc0df689709f3854d67c6d82a757.tar.gz
cpython-99d848bd4ba7bc0df689709f3854d67c6d82a757.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.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/Lib/test/test_pipes.py b/Lib/test/test_pipes.py
index 476bd7c..c8b8be1 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):
- file(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):
- file(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)
with t.open(TESTFN, 'r') as f:
@@ -42,16 +46,20 @@ class SimplePipeTests(unittest.TestCase):
def testEmptyPipeline1(self):
# copy through empty pipe
d = 'empty pipeline test COPY'
- file(TESTFN, 'w').write(d)
- file(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'
- file(TESTFN, 'w').write(d)
+ with open(TESTFN, 'w') as f:
+ f.write(d)
t=pipes.Template()
with t.open(TESTFN, 'r') as f:
self.assertEqual(f.read(), d)
@@ -60,8 +68,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 + '@%_-+=:,./'