test_sndhdr.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pickle
  2. import unittest
  3. from test.support import findfile
  4. from test.support import warnings_helper
  5. sndhdr = warnings_helper.import_deprecated("sndhdr")
  6. class 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. def test_pickleable(self):
  28. filename = findfile('sndhdr.aifc', subdir="sndhdrdata")
  29. what = sndhdr.what(filename)
  30. for proto in range(pickle.HIGHEST_PROTOCOL + 1):
  31. dump = pickle.dumps(what, proto)
  32. self.assertEqual(pickle.loads(dump), what)
  33. if __name__ == '__main__':
  34. unittest.main()