File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -303,6 +303,8 @@ class Aifc_read:
303303 # _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
304304 # _framesize -- size of one frame in the file
305305
306+ _file = None # Set here since __del__ checks it
307+
306308 def initfp (self , file ):
307309 self ._version = 0
308310 self ._convert = None
@@ -547,6 +549,8 @@ class Aifc_write:
547549 # _datalength -- the size of the audio samples written to the header
548550 # _datawritten -- the size of the audio samples actually written
549551
552+ _file = None # Set here since __del__ checks it
553+
550554 def __init__ (self , f ):
551555 if isinstance (f , str ):
552556 file_object = builtins .open (f , 'wb' )
Original file line number Diff line number Diff line change 11from test .support import check_no_resource_warning , findfile , TESTFN , unlink
22import unittest
3+ from unittest import mock
34from test import audiotests
45from audioop import byteswap
56import io
@@ -155,7 +156,14 @@ def test_close_opened_files_on_error(self):
155156 with self .assertRaises (aifc .Error ):
156157 # Try opening a non-AIFC file, with the expectation that
157158 # `aifc.open` will fail (without raising a ResourceWarning)
158- f = self .f = aifc .open (non_aifc_file , 'rb' )
159+ self .f = aifc .open (non_aifc_file , 'rb' )
160+
161+ # Aifc_write.initfp() won't raise in normal case. But some errors
162+ # (e.g. MemoryError, KeyboardInterrupt, etc..) can happen.
163+ with mock .patch .object (aifc .Aifc_write , 'initfp' ,
164+ side_effect = RuntimeError ):
165+ with self .assertRaises (RuntimeError ):
166+ self .fout = aifc .open (TESTFN , 'wb' )
159167
160168 def test_params_added (self ):
161169 f = self .f = aifc .open (TESTFN , 'wb' )
You can’t perform that action at this time.
0 commit comments