All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lib-python.2.7.test.test_wave.py Maven / Gradle / Ivy

Go to download

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

There is a newer version: 2.7.4
Show newest version
from test.test_support import TESTFN, run_unittest
import os
import wave
import unittest

nchannels = 2
sampwidth = 2
framerate = 8000
nframes = 100

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)

def test_main():
    run_unittest(TestWave)

if __name__ == '__main__':
    test_main()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy