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