@@ -191,18 +191,18 @@ def test_read_params(self):
191191 self .sndfilenframes , self .comptype , self .compname )
192192
193193 def test_close (self ):
194- testfile = open (self .sndfilepath , 'rb' )
195- f = self .f = self .module .open (testfile )
196- self .assertFalse (testfile .closed )
197- f .close ()
198- self .assertEqual (testfile .closed , self .close_fd )
199- testfile = open (TESTFN , 'wb' )
200- fout = self .module .open (testfile , 'wb' )
201- self .assertFalse (testfile .closed )
202- with self .assertRaises (self .module .Error ):
203- fout .close ()
204- self .assertEqual (testfile .closed , self .close_fd )
205- fout .close () # do nothing
194+ with open (self .sndfilepath , 'rb' ) as testfile :
195+ f = self .f = self .module .open (testfile )
196+ self .assertFalse (testfile .closed )
197+ f .close ()
198+ self .assertEqual (testfile .closed , self .close_fd )
199+ with open (TESTFN , 'wb' ) as testfile :
200+ fout = self . fout = self .module .open (testfile , 'wb' )
201+ self .assertFalse (testfile .closed )
202+ with self .assertRaises (self .module .Error ):
203+ fout .close ()
204+ self .assertEqual (testfile .closed , self .close_fd )
205+ fout .close () # do nothing
206206
207207 def test_read (self ):
208208 framesize = self .nchannels * self .sampwidth
0 commit comments