/Lib/test/test_aifc.py
Python | 69 lines | 53 code | 13 blank | 3 comment | 1 complexity | fdae2cd4a869eb37e43a3fd4f771a4bc MD5 | raw file
1from test.test_support import findfile, run_unittest 2import unittest 3 4import aifc 5 6 7class AIFCTest(unittest.TestCase): 8 9 def setUp(self): 10 self.sndfilepath = findfile('Sine-1000Hz-300ms.aif') 11 12 def test_skipunknown(self): 13 #Issue 2245 14 #This file contains chunk types aifc doesn't recognize. 15 f = aifc.open(self.sndfilepath) 16 f.close() 17 18 def test_params(self): 19 f = aifc.open(self.sndfilepath) 20 self.assertEqual(f.getnchannels(), 2) 21 self.assertEqual(f.getsampwidth(), 2) 22 self.assertEqual(f.getframerate(), 48000) 23 self.assertEqual(f.getnframes(), 14400) 24 self.assertEqual(f.getcomptype(), 'NONE') 25 self.assertEqual(f.getcompname(), 'not compressed') 26 self.assertEqual(f.getparams(), (2, 2, 48000, 14400, 'NONE', 'not compressed')) 27 f.close() 28 29 def test_read(self): 30 f = aifc.open(self.sndfilepath) 31 self.assertEqual(f.tell(), 0) 32 self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4') 33 f.rewind() 34 pos0 = f.tell() 35 self.assertEqual(pos0, 0) 36 self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4') 37 pos2 = f.tell() 38 self.assertEqual(pos2, 2) 39 self.assertEqual(f.readframes(2), '\x17t\x17t"\xad"\xad') 40 f.setpos(pos2) 41 self.assertEqual(f.readframes(2), '\x17t\x17t"\xad"\xad') 42 f.setpos(pos0) 43 self.assertEqual(f.readframes(2), '\x00\x00\x00\x00\x0b\xd4\x0b\xd4') 44 f.close() 45 46 #XXX Need more tests! 47 48 def test_close(self): 49 class Wrapfile(object): 50 def __init__(self, file): 51 self.file = open(file, 'rb') 52 self.closed = False 53 def close(self): 54 self.file.close() 55 self.closed = True 56 def __getattr__(self, attr): return getattr(self.file, attr) 57 testfile = Wrapfile(self.sndfilepath) 58 f = self.f = aifc.open(testfile) 59 self.assertEqual(testfile.closed, False) 60 f.close() 61 self.assertEqual(testfile.closed, True) 62 63 64def test_main(): 65 run_unittest(AIFCTest) 66 67 68if __name__ == "__main__": 69 unittest.main()