blob: fd411262207cf9ddb620607c8d0f0cc0bce12ffe [file] [log] [blame]
R. David Murrayb507d2e2009-04-29 15:34:32 +00001from 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 # XXX: are the next two correct? The docs say/imply they are supposed
25 # to be strings.
26 self.assertEqual(f.getcomptype(), b'NONE')
27 self.assertEqual(f.getcompname(), b'not compressed')
28 self.assertEqual(
29 f.getparams(),
30 (2, 2, 48000, 14400, b'NONE', b'not compressed'),
31 )
32 f.close()
33
34 def test_read(self):
35 f = aifc.open(self.sndfilepath)
36 self.assertEqual(f.tell(), 0)
37 self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
38 f.rewind()
39 pos0 = f.tell()
40 self.assertEqual(pos0, 0)
41 self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
42 pos2 = f.tell()
43 self.assertEqual(pos2, 2)
44 self.assertEqual(f.readframes(2), b'\x17t\x17t"\xad"\xad')
45 f.setpos(pos2)
46 self.assertEqual(f.readframes(2), b'\x17t\x17t"\xad"\xad')
47 f.setpos(pos0)
48 self.assertEqual(f.readframes(2), b'\x00\x00\x00\x00\x0b\xd4\x0b\xd4')
49 f.close()
50
51 #XXX Need more tests!
52
53
54def test_main():
55 run_unittest(AIFCTest)
56
57
58if __name__ == "__main__":
59 unittest.main()