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:
303
303
# _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
304
304
# _framesize -- size of one frame in the file
305
305
306
+ _file = None # Set here since __del__ checks it
307
+
306
308
def initfp (self , file ):
307
309
self ._version = 0
308
310
self ._convert = None
@@ -547,6 +549,8 @@ class Aifc_write:
547
549
# _datalength -- the size of the audio samples written to the header
548
550
# _datawritten -- the size of the audio samples actually written
549
551
552
+ _file = None # Set here since __del__ checks it
553
+
550
554
def __init__ (self , f ):
551
555
if isinstance (f , str ):
552
556
file_object = builtins .open (f , 'wb' )
Original file line number Diff line number Diff line change 1
1
from test .support import check_no_resource_warning , findfile , TESTFN , unlink
2
2
import unittest
3
+ from unittest import mock
3
4
from test import audiotests
4
5
from audioop import byteswap
5
6
import io
@@ -155,7 +156,14 @@ def test_close_opened_files_on_error(self):
155
156
with self .assertRaises (aifc .Error ):
156
157
# Try opening a non-AIFC file, with the expectation that
157
158
# `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' )
159
167
160
168
def test_params_added (self ):
161
169
f = self .f = aifc .open (TESTFN , 'wb' )
You can’t perform that action at this time.
0 commit comments