1 | n/a | import sndhdr |
---|
2 | n/a | import pickle |
---|
3 | n/a | import unittest |
---|
4 | n/a | from test.support import findfile |
---|
5 | n/a | |
---|
6 | n/a | class TestFormats(unittest.TestCase): |
---|
7 | n/a | def test_data(self): |
---|
8 | n/a | for filename, expected in ( |
---|
9 | n/a | ('sndhdr.8svx', ('8svx', 0, 1, 0, 8)), |
---|
10 | n/a | ('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)), |
---|
11 | n/a | ('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)), |
---|
12 | n/a | ('sndhdr.au', ('au', 44100, 2, 5.0, 16)), |
---|
13 | n/a | ('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)), |
---|
14 | n/a | ('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)), |
---|
15 | n/a | ('sndhdr.voc', ('voc', 0, 1, -1, 8)), |
---|
16 | n/a | ('sndhdr.wav', ('wav', 44100, 2, 5, 16)), |
---|
17 | n/a | ): |
---|
18 | n/a | filename = findfile(filename, subdir="sndhdrdata") |
---|
19 | n/a | what = sndhdr.what(filename) |
---|
20 | n/a | self.assertNotEqual(what, None, filename) |
---|
21 | n/a | self.assertSequenceEqual(what, expected) |
---|
22 | n/a | self.assertEqual(what.filetype, expected[0]) |
---|
23 | n/a | self.assertEqual(what.framerate, expected[1]) |
---|
24 | n/a | self.assertEqual(what.nchannels, expected[2]) |
---|
25 | n/a | self.assertEqual(what.nframes, expected[3]) |
---|
26 | n/a | self.assertEqual(what.sampwidth, expected[4]) |
---|
27 | n/a | |
---|
28 | n/a | def test_pickleable(self): |
---|
29 | n/a | filename = findfile('sndhdr.aifc', subdir="sndhdrdata") |
---|
30 | n/a | what = sndhdr.what(filename) |
---|
31 | n/a | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
---|
32 | n/a | dump = pickle.dumps(what, proto) |
---|
33 | n/a | self.assertEqual(pickle.loads(dump), what) |
---|
34 | n/a | |
---|
35 | n/a | |
---|
36 | n/a | if __name__ == '__main__': |
---|
37 | n/a | unittest.main() |
---|