@@ -23,43 +23,53 @@ def testSimplePipe1(self):
2323 f = t .open (TESTFN , 'w' )
2424 f .write ('hello world #1' )
2525 f .close ()
26- self .assertEqual (open (TESTFN ).read (), 'HELLO WORLD #1' )
26+ with open (TESTFN ) as f :
27+ self .assertEqual (f .read (), 'HELLO WORLD #1' )
2728
2829 def testSimplePipe2 (self ):
29- open (TESTFN , 'w' ).write ('hello world #2' )
30+ with open (TESTFN , 'w' ) as f :
31+ f .write ('hello world #2' )
3032 t = pipes .Template ()
3133 t .append (s_command + ' < $IN > $OUT' , pipes .FILEIN_FILEOUT )
3234 t .copy (TESTFN , TESTFN2 )
33- self .assertEqual (open (TESTFN2 ).read (), 'HELLO WORLD #2' )
35+ with open (TESTFN2 ) as f :
36+ self .assertEqual (f .read (), 'HELLO WORLD #2' )
3437
3538 def testSimplePipe3 (self ):
36- open (TESTFN , 'w' ).write ('hello world #2' )
39+ with open (TESTFN , 'w' ) as f :
40+ f .write ('hello world #2' )
3741 t = pipes .Template ()
3842 t .append (s_command + ' < $IN' , pipes .FILEIN_STDOUT )
3943 self .assertEqual (t .open (TESTFN , 'r' ).read (), 'HELLO WORLD #2' )
4044
4145 def testEmptyPipeline1 (self ):
4246 # copy through empty pipe
4347 d = 'empty pipeline test COPY'
44- open (TESTFN , 'w' ).write (d )
45- open (TESTFN2 , 'w' ).write ('' )
48+ with open (TESTFN , 'w' ) as f :
49+ f .write (d )
50+ with open (TESTFN2 , 'w' ) as f :
51+ f .write ('' )
4652 t = pipes .Template ()
4753 t .copy (TESTFN , TESTFN2 )
48- self .assertEqual (open (TESTFN2 ).read (), d )
54+ with open (TESTFN2 ) as f :
55+ self .assertEqual (f .read (), d )
4956
5057 def testEmptyPipeline2 (self ):
5158 # read through empty pipe
5259 d = 'empty pipeline test READ'
53- open (TESTFN , 'w' ).write (d )
60+ with open (TESTFN , 'w' ) as f :
61+ f .write (d )
5462 t = pipes .Template ()
5563 self .assertEqual (t .open (TESTFN , 'r' ).read (), d )
5664
5765 def testEmptyPipeline3 (self ):
5866 # write through empty pipe
5967 d = 'empty pipeline test WRITE'
6068 t = pipes .Template ()
61- t .open (TESTFN , 'w' ).write (d )
62- self .assertEqual (open (TESTFN ).read (), d )
69+ with t .open (TESTFN , 'w' ) as f :
70+ f .write (d )
71+ with open (TESTFN ) as f :
72+ self .assertEqual (f .read (), d )
6373
6474 def testQuoting (self ):
6575 safeunquoted = string .ascii_letters + string .digits + '@%_-+=:,./'
0 commit comments