home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_wave.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  755 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, 'wb')
  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, 'rb')
  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.