Home | History | Annotate | Download | only in test
      1 from test.test_support import TESTFN, run_unittest
      2 import os
      3 import wave
      4 import unittest
      5 
      6 nchannels = 2
      7 sampwidth = 2
      8 framerate = 8000
      9 nframes = 100
     10 
     11 class TestWave(unittest.TestCase):
     12 
     13     def setUp(self):
     14         self.f = None
     15 
     16     def tearDown(self):
     17         if self.f is not None:
     18             self.f.close()
     19         try:
     20             os.remove(TESTFN)
     21         except OSError:
     22             pass
     23 
     24     def test_it(self):
     25         self.f = wave.open(TESTFN, 'wb')
     26         self.f.setnchannels(nchannels)
     27         self.f.setsampwidth(sampwidth)
     28         self.f.setframerate(framerate)
     29         self.f.setnframes(nframes)
     30         output = '\0' * nframes * nchannels * sampwidth
     31         self.f.writeframes(output)
     32         self.f.close()
     33 
     34         self.f = wave.open(TESTFN, 'rb')
     35         self.assertEqual(nchannels, self.f.getnchannels())
     36         self.assertEqual(sampwidth, self.f.getsampwidth())
     37         self.assertEqual(framerate, self.f.getframerate())
     38         self.assertEqual(nframes, self.f.getnframes())
     39         self.assertEqual(self.f.readframes(nframes), output)
     40 
     41 def test_main():
     42     run_unittest(TestWave)
     43 
     44 if __name__ == '__main__':
     45     test_main()
     46