Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(11843)

Side by Side Diff: Lib/test/test_aifc.py

Issue 18919: Unify audio modules tests
Patch Set: Created 5 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from test.test_support import findfile, TESTFN, unlink, run_unittest 1 from test.test_support import findfile, TESTFN, unlink, captured_stdout, run_uni ttest
2 import unittest 2 import unittest
3 from test import audiotests 3 from test import audiotests
4 import os 4 import os
5 import io 5 import io
6 import sys 6 import sys
7 import struct 7 import struct
8 import aifc 8 import aifc
9 9
10 10
11 class AifcPCM8Test(audiotests.AudioWriteTests, 11 class AifcPCM8Test(audiotests.AudioWriteTests,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 b = 'FORM' + struct.pack('>L', 4) + 'AIFC' 218 b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
219 b += 'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0) 219 b += 'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)
220 b += 'WRNG' + struct.pack('B', 0) 220 b += 'WRNG' + struct.pack('B', 0)
221 self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b)) 221 self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b))
222 222
223 def test_read_wrong_marks(self): 223 def test_read_wrong_marks(self):
224 b = 'FORM' + struct.pack('>L', 4) + 'AIFF' 224 b = 'FORM' + struct.pack('>L', 4) + 'AIFF'
225 b += 'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) 225 b += 'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
226 b += 'SSND' + struct.pack('>L', 8) + '\x00' * 8 226 b += 'SSND' + struct.pack('>L', 8) + '\x00' * 8
227 b += 'MARK' + struct.pack('>LhB', 3, 1, 1) 227 b += 'MARK' + struct.pack('>LhB', 3, 1, 1)
228 f = aifc.open(io.BytesIO(b)) 228 with captured_stdout() as s:
229 f = aifc.open(io.BytesIO(b))
230 self.assertEqual(s.getvalue(), 'Warning: MARK chunk contains only '
231 '0 markers instead of 1\n')
229 self.assertEqual(f.getmarkers(), None) 232 self.assertEqual(f.getmarkers(), None)
230 233
231 def test_read_comm_kludge_compname_even(self): 234 def test_read_comm_kludge_compname_even(self):
232 b = 'FORM' + struct.pack('>L', 4) + 'AIFC' 235 b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
233 b += 'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) 236 b += 'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
234 b += 'NONE' + struct.pack('B', 4) + 'even' + '\x00' 237 b += 'NONE' + struct.pack('B', 4) + 'even' + '\x00'
235 b += 'SSND' + struct.pack('>L', 8) + '\x00' * 8 238 b += 'SSND' + struct.pack('>L', 8) + '\x00' * 8
236 f = aifc.open(io.BytesIO(b)) 239 with captured_stdout() as s:
240 f = aifc.open(io.BytesIO(b))
241 self.assertEqual(s.getvalue(), 'Warning: bad COMM chunk size\n')
237 self.assertEqual(f.getcompname(), 'even') 242 self.assertEqual(f.getcompname(), 'even')
238 243
239 def test_read_comm_kludge_compname_odd(self): 244 def test_read_comm_kludge_compname_odd(self):
240 b = 'FORM' + struct.pack('>L', 4) + 'AIFC' 245 b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
241 b += 'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0) 246 b += 'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
242 b += 'NONE' + struct.pack('B', 3) + 'odd' 247 b += 'NONE' + struct.pack('B', 3) + 'odd'
243 b += 'SSND' + struct.pack('>L', 8) + '\x00' * 8 248 b += 'SSND' + struct.pack('>L', 8) + '\x00' * 8
244 f = aifc.open(io.BytesIO(b)) 249 with captured_stdout() as s:
250 f = aifc.open(io.BytesIO(b))
251 self.assertEqual(s.getvalue(), 'Warning: bad COMM chunk size\n')
245 self.assertEqual(f.getcompname(), 'odd') 252 self.assertEqual(f.getcompname(), 'odd')
246 253
247 def test_write_params_raises(self): 254 def test_write_params_raises(self):
248 fout = aifc.open(io.BytesIO(), 'wb') 255 fout = aifc.open(io.BytesIO(), 'wb')
249 wrong_params = (0, 0, 0, 0, 'WRNG', '') 256 wrong_params = (0, 0, 0, 0, 'WRNG', '')
250 self.assertRaises(aifc.Error, fout.setparams, wrong_params) 257 self.assertRaises(aifc.Error, fout.setparams, wrong_params)
251 self.assertRaises(aifc.Error, fout.getparams) 258 self.assertRaises(aifc.Error, fout.getparams)
252 self.assertRaises(aifc.Error, fout.setnchannels, 0) 259 self.assertRaises(aifc.Error, fout.setnchannels, 0)
253 self.assertRaises(aifc.Error, fout.getnchannels) 260 self.assertRaises(aifc.Error, fout.getnchannels)
254 self.assertRaises(aifc.Error, fout.setsampwidth, 0) 261 self.assertRaises(aifc.Error, fout.setsampwidth, 0)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 f.close() 344 f.close()
338 345
339 346
340 def test_main(): 347 def test_main():
341 run_unittest(AifcPCM8Test, AifcPCM16Test, AifcPCM16Test, AifcPCM24Test, 348 run_unittest(AifcPCM8Test, AifcPCM16Test, AifcPCM16Test, AifcPCM24Test,
342 AifcPCM32Test, AifcULAWTest, 349 AifcPCM32Test, AifcULAWTest,
343 AifcMiscTest, AIFCLowLevelTest) 350 AifcMiscTest, AIFCLowLevelTest)
344 351
345 if __name__ == "__main__": 352 if __name__ == "__main__":
346 test_main() 353 test_main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+