2008-02-05 15:03:32 -04:00
|
|
|
from test.test_support import TESTFN, run_unittest
|
2002-08-09 13:38:32 -03:00
|
|
|
import os
|
2000-10-09 17:05:59 -03:00
|
|
|
import wave
|
2008-02-05 15:03:32 -04:00
|
|
|
import unittest
|
2000-10-09 17:05:59 -03:00
|
|
|
|
|
|
|
nchannels = 2
|
|
|
|
sampwidth = 2
|
|
|
|
framerate = 8000
|
|
|
|
nframes = 100
|
|
|
|
|
2008-02-05 15:03:32 -04:00
|
|
|
class TestWave(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.f = None
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
if self.f is not None:
|
|
|
|
self.f.close()
|
|
|
|
try:
|
|
|
|
os.remove(TESTFN)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_it(self):
|
|
|
|
self.f = wave.open(TESTFN, 'wb')
|
|
|
|
self.f.setnchannels(nchannels)
|
|
|
|
self.f.setsampwidth(sampwidth)
|
|
|
|
self.f.setframerate(framerate)
|
|
|
|
self.f.setnframes(nframes)
|
|
|
|
output = '\0' * nframes * nchannels * sampwidth
|
|
|
|
self.f.writeframes(output)
|
|
|
|
self.f.close()
|
|
|
|
|
|
|
|
self.f = wave.open(TESTFN, 'rb')
|
|
|
|
self.assertEqual(nchannels, self.f.getnchannels())
|
|
|
|
self.assertEqual(sampwidth, self.f.getsampwidth())
|
|
|
|
self.assertEqual(framerate, self.f.getframerate())
|
|
|
|
self.assertEqual(nframes, self.f.getnframes())
|
|
|
|
self.assertEqual(self.f.readframes(nframes), output)
|
|
|
|
|
2008-02-05 15:07:10 -04:00
|
|
|
def test_main():
|
2008-02-05 15:03:32 -04:00
|
|
|
run_unittest(TestWave)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2008-02-05 15:07:10 -04:00
|
|
|
test_main()
|