@@ -141,18 +141,18 @@ def test_read_params(self):
141141 self .sndfilenframes , self .comptype , self .compname )
142142
143143 def test_close (self ):
144- testfile = open (self .sndfilepath , 'rb' )
145- f = self .f = self .module .open (testfile )
146- self .assertFalse (testfile .closed )
147- f .close ()
148- self .assertEqual (testfile .closed , self .close_fd )
149- testfile = open (TESTFN , 'wb' )
150- fout = self .module .open (testfile , 'wb' )
151- self .assertFalse (testfile .closed )
152- with self .assertRaises (self .module .Error ):
153- fout .close ()
154- self .assertEqual (testfile .closed , self .close_fd )
155- fout .close () # do nothing
144+ with open (self .sndfilepath , 'rb' ) as testfile :
145+ f = self .f = self .module .open (testfile )
146+ self .assertFalse (testfile .closed )
147+ f .close ()
148+ self .assertEqual (testfile .closed , self .close_fd )
149+ with open (TESTFN , 'wb' ) as testfile :
150+ fout = self . fout = self .module .open (testfile , 'wb' )
151+ self .assertFalse (testfile .closed )
152+ with self .assertRaises (self .module .Error ):
153+ fout .close ()
154+ self .assertEqual (testfile .closed , self .close_fd )
155+ fout .close () # do nothing
156156
157157 def test_read (self ):
158158 framesize = self .nchannels * self .sampwidth
0 commit comments