home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_WAVE.PY < prev    next >
Encoding:
Python Source  |  2000-10-09  |  787 b   |  35 lines

  1. from test_support import TestFailed
  2. import os, tempfile
  3. import wave
  4.  
  5. def check(t, msg=None):
  6.     if not t:
  7.         raise TestFailed, msg
  8.  
  9. nchannels = 2
  10. sampwidth = 2
  11. framerate = 8000
  12. nframes = 100
  13.  
  14. testfile = tempfile.mktemp()
  15.  
  16. f = wave.open(testfile, 'w')
  17. f.setnchannels(nchannels)
  18. f.setsampwidth(sampwidth)
  19. f.setframerate(framerate)
  20. f.setnframes(nframes)
  21. output = '\0' * nframes * nchannels * sampwidth
  22. f.writeframes(output)
  23. f.close()
  24.  
  25. f = wave.open(testfile, 'r')
  26. check(nchannels == f.getnchannels(), "nchannels")
  27. check(sampwidth == f.getsampwidth(), "sampwidth")
  28. check(framerate == f.getframerate(), "framerate")
  29. check(nframes == f.getnframes(), "nframes")
  30. input = f.readframes(nframes)
  31. check(input == output, "data")
  32. f.close()
  33.  
  34. os.remove(testfile)
  35.