[Python-checkins] r81809 - in python/branches/py3k: Lib/sunau.py Lib/test/test_sunau.py Misc/ACKS Misc/NEWS
victor.stinner
python-checkins at python.org
Mon Jun 7 22:14:04 CEST 2010
Author: victor.stinner
Date: Mon Jun 7 22:14:04 2010
New Revision: 81809
Log:
Issue #8897: Fix sunau module, use bytes to write the header. Patch written by
Thomas Jollans.
Added:
python/branches/py3k/Lib/test/test_sunau.py
Modified:
python/branches/py3k/Lib/sunau.py
python/branches/py3k/Misc/ACKS
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/sunau.py
==============================================================================
--- python/branches/py3k/Lib/sunau.py (original)
+++ python/branches/py3k/Lib/sunau.py Mon Jun 7 22:14:04 2010
@@ -299,7 +299,7 @@
self._nframeswritten = 0
self._datawritten = 0
self._datalength = 0
- self._info = ''
+ self._info = b''
self._comptype = 'ULAW' # default is U-law
def setnchannels(self, nchannels):
Added: python/branches/py3k/Lib/test/test_sunau.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/test_sunau.py Mon Jun 7 22:14:04 2010
@@ -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()
Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS (original)
+++ python/branches/py3k/Misc/ACKS Mon Jun 7 22:14:04 2010
@@ -389,6 +389,7 @@
Fredrik Johansson
Gregory K. Johnson
Simon Johnston
+Thomas Jollans
Evan Jones
Jeremy Jones
Richard Jones
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Mon Jun 7 22:14:04 2010
@@ -398,6 +398,9 @@
Library
-------
+- Issue #8897: Fix sunau module, use bytes to write the header. Patch written
+ by Thomas Jollans.
+
- Issue #8899: time.struct_time now has class and atribute docstrings.
- Issue #6470: Drop UNC prefix in FixTk.
More information about the Python-checkins
mailing list