R. David Murray | 25b4add | 2009-04-29 13:17:37 +0000 | [diff] [blame] | 1 | from test.test_support import findfile, run_unittest |
| 2 | import unittest |
| 3 | |
| 4 | import aifc |
| 5 | |
| 6 | |
| 7 | class 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 | |
R. David Murray | 971b1b1 | 2009-04-29 13:51:44 +0000 | [diff] [blame^] | 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 | |
R. David Murray | 25b4add | 2009-04-29 13:17:37 +0000 | [diff] [blame] | 48 | |
| 49 | def test_main(): |
| 50 | run_unittest(AIFCTest) |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | unittest.main() |