0001 from test.test_support import TestFailed, TESTFN 0002 import os 0003 import wave 0004 0005 def check(t, msg=None): 0006 if not t: 0007 raise TestFailed, msg 0008 0009 nchannels = 2 0010 sampwidth = 2 0011 framerate = 8000 0012 nframes = 100 0013 0014 f = wave.open(TESTFN, 'wb') 0015 f.setnchannels(nchannels) 0016 f.setsampwidth(sampwidth) 0017 f.setframerate(framerate) 0018 f.setnframes(nframes) 0019 output = '\0' * nframes * nchannels * sampwidth 0020 f.writeframes(output) 0021 f.close() 0022 0023 f = wave.open(TESTFN, 'rb') 0024 check(nchannels == f.getnchannels(), "nchannels") 0025 check(sampwidth == f.getsampwidth(), "sampwidth") 0026 check(framerate == f.getframerate(), "framerate") 0027 check(nframes == f.getnframes(), "nframes") 0028 input = f.readframes(nframes) 0029 check(input == output, "data") 0030 f.close() 0031 0032 os.remove(TESTFN) 0033
Generated by PyXR 0.9.4