Guido van Rossum | a00afc1 | 2000-10-09 20:05:59 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | 70f1288 | 2000-12-19 06:32:57 +0000 | [diff] [blame^] | 16 | f = wave.open(testfile, 'wb') |
Guido van Rossum | a00afc1 | 2000-10-09 20:05:59 +0000 | [diff] [blame] | 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 | |
Guido van Rossum | 70f1288 | 2000-12-19 06:32:57 +0000 | [diff] [blame^] | 25 | f = wave.open(testfile, 'rb') |
Guido van Rossum | a00afc1 | 2000-10-09 20:05:59 +0000 | [diff] [blame] | 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) |