Merged release21-maint changes.
[python/dscho.git] / Lib / test / test_wave.py
blobe2dc68892ddb95238541ffde705725ec5dea47a9
1 from test_support import TestFailed
2 import os, tempfile
3 import wave
5 def check(t, msg=None):
6 if not t:
7 raise TestFailed, msg
9 nchannels = 2
10 sampwidth = 2
11 framerate = 8000
12 nframes = 100
14 testfile = tempfile.mktemp()
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()
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()
34 os.remove(testfile)