mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
bpo-32056: Improve exceptions in aifc, wave and sunau. (GH-5951)
This commit is contained in:
parent
bc300ce205
commit
134cb01cda
7 changed files with 150 additions and 7 deletions
|
@ -268,7 +268,8 @@ class AIFCLowLevelTest(unittest.TestCase):
|
|||
|
||||
def test_read_no_ssnd_chunk(self):
|
||||
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 38, 1, 0, 8,
|
||||
0x4000 | 12, 11025<<18, 0)
|
||||
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
|
||||
with self.assertRaisesRegex(aifc.Error, 'COMM chunk and/or SSND chunk'
|
||||
' missing'):
|
||||
|
@ -276,13 +277,35 @@ class AIFCLowLevelTest(unittest.TestCase):
|
|||
|
||||
def test_read_wrong_compression_type(self):
|
||||
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 23, 1, 0, 8,
|
||||
0x4000 | 12, 11025<<18, 0)
|
||||
b += b'WRNG' + struct.pack('B', 0)
|
||||
self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b))
|
||||
|
||||
def test_read_wrong_number_of_channels(self):
|
||||
for nchannels in 0, -1:
|
||||
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 38, nchannels, 0, 8,
|
||||
0x4000 | 12, 11025<<18, 0)
|
||||
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
|
||||
b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
|
||||
with self.assertRaisesRegex(aifc.Error, 'bad # of channels'):
|
||||
aifc.open(io.BytesIO(b))
|
||||
|
||||
def test_read_wrong_sample_width(self):
|
||||
for sampwidth in 0, -1:
|
||||
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 38, 1, 0, sampwidth,
|
||||
0x4000 | 12, 11025<<18, 0)
|
||||
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
|
||||
b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
|
||||
with self.assertRaisesRegex(aifc.Error, 'bad sample width'):
|
||||
aifc.open(io.BytesIO(b))
|
||||
|
||||
def test_read_wrong_marks(self):
|
||||
b = b'FORM' + struct.pack('>L', 4) + b'AIFF'
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 18, 1, 0, 8,
|
||||
0x4000 | 12, 11025<<18, 0)
|
||||
b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
|
||||
b += b'MARK' + struct.pack('>LhB', 3, 1, 1)
|
||||
with self.assertWarns(UserWarning) as cm:
|
||||
|
@ -293,7 +316,8 @@ class AIFCLowLevelTest(unittest.TestCase):
|
|||
|
||||
def test_read_comm_kludge_compname_even(self):
|
||||
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 18, 1, 0, 8,
|
||||
0x4000 | 12, 11025<<18, 0)
|
||||
b += b'NONE' + struct.pack('B', 4) + b'even' + b'\x00'
|
||||
b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
|
||||
with self.assertWarns(UserWarning) as cm:
|
||||
|
@ -303,7 +327,8 @@ class AIFCLowLevelTest(unittest.TestCase):
|
|||
|
||||
def test_read_comm_kludge_compname_odd(self):
|
||||
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
|
||||
b += b'COMM' + struct.pack('>LhlhhLL', 18, 1, 0, 8,
|
||||
0x4000 | 12, 11025<<18, 0)
|
||||
b += b'NONE' + struct.pack('B', 3) + b'odd'
|
||||
b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
|
||||
with self.assertWarns(UserWarning) as cm:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue