diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-07 20:14:04 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-07 20:14:04 (GMT) |
commit | 7f3652e37156a4794c04a70e93c339d7d58a52f2 (patch) | |
tree | abd6510f72195675f53eebbba41d7100aea11ea0 /Lib/test/test_sunau.py | |
parent | 7eeb5b5e5017cf1354b084327b49390044946069 (diff) | |
download | cpython-7f3652e37156a4794c04a70e93c339d7d58a52f2.zip cpython-7f3652e37156a4794c04a70e93c339d7d58a52f2.tar.gz cpython-7f3652e37156a4794c04a70e93c339d7d58a52f2.tar.bz2 |
Issue #8897: Fix sunau module, use bytes to write the header. Patch written by
Thomas Jollans.
Diffstat (limited to 'Lib/test/test_sunau.py')
-rw-r--r-- | Lib/test/test_sunau.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py new file mode 100644 index 0000000..339ab57 --- /dev/null +++ b/Lib/test/test_sunau.py @@ -0,0 +1,70 @@ +from test.support import run_unittest, TESTFN +import unittest +import os + +import sunau + +nchannels = 2 +sampwidth = 2 +framerate = 8000 +nframes = 100 + +class SunAUTest(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_lin(self): + self.f = sunau.open(TESTFN, 'w') + self.f.setnchannels(nchannels) + self.f.setsampwidth(sampwidth) + self.f.setframerate(framerate) + self.f.setcomptype('NONE', 'not compressed') + output = b'\xff\x00\x12\xcc' * (nframes * nchannels * sampwidth // 4) + self.f.writeframes(output) + self.f.close() + + self.f = sunau.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('NONE', self.f.getcomptype()) + self.assertEqual(self.f.readframes(nframes), output) + self.f.close() + + def test_ulaw(self): + self.f = sunau.open(TESTFN, 'w') + self.f.setnchannels(nchannels) + self.f.setsampwidth(sampwidth) + self.f.setframerate(framerate) + self.f.setcomptype('ULAW', '') + # u-law compression is lossy, therefore we can't expect non-zero data + # to come back unchanged. + output = b'\0' * nframes * nchannels * sampwidth + self.f.writeframes(output) + self.f.close() + + self.f = sunau.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('ULAW', self.f.getcomptype()) + self.assertEqual(self.f.readframes(nframes), output) + self.f.close() + + +def test_main(): + run_unittest(SunAUTest) + +if __name__ == "__main__": + unittest.main() |