blob: e2dc68892ddb95238541ffde705725ec5dea47a9 [file] [log] [blame]
Guido van Rossuma00afc12000-10-09 20:05:59 +00001from test_support import TestFailed
2import os, tempfile
3import wave
4
5def check(t, msg=None):
6 if not t:
7 raise TestFailed, msg
8
9nchannels = 2
10sampwidth = 2
11framerate = 8000
12nframes = 100
13
14testfile = tempfile.mktemp()
15
Guido van Rossum70f12882000-12-19 06:32:57 +000016f = wave.open(testfile, 'wb')
Guido van Rossuma00afc12000-10-09 20:05:59 +000017f.setnchannels(nchannels)
18f.setsampwidth(sampwidth)
19f.setframerate(framerate)
20f.setnframes(nframes)
21output = '\0' * nframes * nchannels * sampwidth
22f.writeframes(output)
23f.close()
24
Guido van Rossum70f12882000-12-19 06:32:57 +000025f = wave.open(testfile, 'rb')
Guido van Rossuma00afc12000-10-09 20:05:59 +000026check(nchannels == f.getnchannels(), "nchannels")
27check(sampwidth == f.getsampwidth(), "sampwidth")
28check(framerate == f.getframerate(), "framerate")
29check(nframes == f.getnframes(), "nframes")
30input = f.readframes(nframes)
31check(input == output, "data")
32f.close()
33
34os.remove(testfile)