@@ -23,17 +23,21 @@ 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 f = t .open (TESTFN , 'r' )
@@ -45,16 +49,20 @@ def testSimplePipe3(self):
4549 def testEmptyPipeline1 (self ):
4650 # copy through empty pipe
4751 d = 'empty pipeline test COPY'
48- open (TESTFN , 'w' ).write (d )
49- open (TESTFN2 , 'w' ).write ('' )
52+ with open (TESTFN , 'w' ) as f :
53+ f .write (d )
54+ with open (TESTFN2 , 'w' ) as f :
55+ f .write ('' )
5056 t = pipes .Template ()
5157 t .copy (TESTFN , TESTFN2 )
52- self .assertEqual (open (TESTFN2 ).read (), d )
58+ with open (TESTFN2 ) as f :
59+ self .assertEqual (f .read (), d )
5360
5461 def testEmptyPipeline2 (self ):
5562 # read through empty pipe
5663 d = 'empty pipeline test READ'
57- open (TESTFN , 'w' ).write (d )
64+ with open (TESTFN , 'w' ) as f :
65+ f .write (d )
5866 t = pipes .Template ()
5967 f = t .open (TESTFN , 'r' )
6068 try :
@@ -66,8 +74,10 @@ def testEmptyPipeline3(self):
6674 # write through empty pipe
6775 d = 'empty pipeline test WRITE'
6876 t = pipes .Template ()
69- t .open (TESTFN , 'w' ).write (d )
70- self .assertEqual (open (TESTFN ).read (), d )
77+ with t .open (TESTFN , 'w' ) as f :
78+ f .write (d )
79+ with open (TESTFN ) as f :
80+ self .assertEqual (f .read (), d )
7181
7282 def testQuoting (self ):
7383 safeunquoted = string .ascii_letters + string .digits + '@%_-+=:,./'
0 commit comments