@@ -265,21 +265,44 @@ def test_read_no_comm_chunk(self):
265
265
266
266
def test_read_no_ssnd_chunk (self ):
267
267
b = b'FORM' + struct .pack ('>L' , 4 ) + b'AIFC'
268
- b += b'COMM' + struct .pack ('>LhlhhLL' , 38 , 0 , 0 , 0 , 0 , 0 , 0 )
268
+ b += b'COMM' + struct .pack ('>LhlhhLL' , 38 , 1 , 0 , 8 ,
269
+ 0x4000 | 12 , 11025 << 18 , 0 )
269
270
b += b'NONE' + struct .pack ('B' , 14 ) + b'not compressed' + b'\x00 '
270
271
with self .assertRaisesRegex (aifc .Error , 'COMM chunk and/or SSND chunk'
271
272
' missing' ):
272
273
aifc .open (io .BytesIO (b ))
273
274
274
275
def test_read_wrong_compression_type (self ):
275
276
b = b'FORM' + struct .pack ('>L' , 4 ) + b'AIFC'
276
- b += b'COMM' + struct .pack ('>LhlhhLL' , 23 , 0 , 0 , 0 , 0 , 0 , 0 )
277
+ b += b'COMM' + struct .pack ('>LhlhhLL' , 23 , 1 , 0 , 8 ,
278
+ 0x4000 | 12 , 11025 << 18 , 0 )
277
279
b += b'WRNG' + struct .pack ('B' , 0 )
278
280
self .assertRaises (aifc .Error , aifc .open , io .BytesIO (b ))
279
281
282
+ def test_read_wrong_number_of_channels (self ):
283
+ for nchannels in 0 , - 1 :
284
+ b = b'FORM' + struct .pack ('>L' , 4 ) + b'AIFC'
285
+ b += b'COMM' + struct .pack ('>LhlhhLL' , 38 , nchannels , 0 , 8 ,
286
+ 0x4000 | 12 , 11025 << 18 , 0 )
287
+ b += b'NONE' + struct .pack ('B' , 14 ) + b'not compressed' + b'\x00 '
288
+ b += b'SSND' + struct .pack ('>L' , 8 ) + b'\x00 ' * 8
289
+ with self .assertRaisesRegex (aifc .Error , 'bad # of channels' ):
290
+ aifc .open (io .BytesIO (b ))
291
+
292
+ def test_read_wrong_sample_width (self ):
293
+ for sampwidth in 0 , - 1 :
294
+ b = b'FORM' + struct .pack ('>L' , 4 ) + b'AIFC'
295
+ b += b'COMM' + struct .pack ('>LhlhhLL' , 38 , 1 , 0 , sampwidth ,
296
+ 0x4000 | 12 , 11025 << 18 , 0 )
297
+ b += b'NONE' + struct .pack ('B' , 14 ) + b'not compressed' + b'\x00 '
298
+ b += b'SSND' + struct .pack ('>L' , 8 ) + b'\x00 ' * 8
299
+ with self .assertRaisesRegex (aifc .Error , 'bad sample width' ):
300
+ aifc .open (io .BytesIO (b ))
301
+
280
302
def test_read_wrong_marks (self ):
281
303
b = b'FORM' + struct .pack ('>L' , 4 ) + b'AIFF'
282
- b += b'COMM' + struct .pack ('>LhlhhLL' , 18 , 0 , 0 , 0 , 0 , 0 , 0 )
304
+ b += b'COMM' + struct .pack ('>LhlhhLL' , 18 , 1 , 0 , 8 ,
305
+ 0x4000 | 12 , 11025 << 18 , 0 )
283
306
b += b'SSND' + struct .pack ('>L' , 8 ) + b'\x00 ' * 8
284
307
b += b'MARK' + struct .pack ('>LhB' , 3 , 1 , 1 )
285
308
with self .assertWarns (UserWarning ) as cm :
@@ -290,7 +313,8 @@ def test_read_wrong_marks(self):
290
313
291
314
def test_read_comm_kludge_compname_even (self ):
292
315
b = b'FORM' + struct .pack ('>L' , 4 ) + b'AIFC'
293
- b += b'COMM' + struct .pack ('>LhlhhLL' , 18 , 0 , 0 , 0 , 0 , 0 , 0 )
316
+ b += b'COMM' + struct .pack ('>LhlhhLL' , 18 , 1 , 0 , 8 ,
317
+ 0x4000 | 12 , 11025 << 18 , 0 )
294
318
b += b'NONE' + struct .pack ('B' , 4 ) + b'even' + b'\x00 '
295
319
b += b'SSND' + struct .pack ('>L' , 8 ) + b'\x00 ' * 8
296
320
with self .assertWarns (UserWarning ) as cm :
@@ -300,7 +324,8 @@ def test_read_comm_kludge_compname_even(self):
300
324
301
325
def test_read_comm_kludge_compname_odd (self ):
302
326
b = b'FORM' + struct .pack ('>L' , 4 ) + b'AIFC'
303
- b += b'COMM' + struct .pack ('>LhlhhLL' , 18 , 0 , 0 , 0 , 0 , 0 , 0 )
327
+ b += b'COMM' + struct .pack ('>LhlhhLL' , 18 , 1 , 0 , 8 ,
328
+ 0x4000 | 12 , 11025 << 18 , 0 )
304
329
b += b'NONE' + struct .pack ('B' , 3 ) + b'odd'
305
330
b += b'SSND' + struct .pack ('>L' , 8 ) + b'\x00 ' * 8
306
331
with self .assertWarns (UserWarning ) as cm :
0 commit comments