]> granicus.if.org Git - python/commitdiff
Merged revisions 81809 via svnmerge from
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 7 Jun 2010 20:24:48 +0000 (20:24 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 7 Jun 2010 20:24:48 +0000 (20:24 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r81809 | victor.stinner | 2010-06-07 22:14:04 +0200 (lun., 07 juin 2010) | 3 lines

  Issue #8897: Fix sunau module, use bytes to write the header. Patch written by
  Thomas Jollans.
........

Lib/sunau.py
Lib/test/test_sunau.py [new file with mode: 0644]
Misc/ACKS
Misc/NEWS

index 4d07f431bc105ced422f0834d9b5ecc36014c183..5f50e8fb9c96490dc1190e3273c0ef751be2de11 100644 (file)
@@ -299,7 +299,7 @@ class Au_write:
         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):
diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py
new file mode 100644 (file)
index 0000000..339ab57
--- /dev/null
@@ -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()
index 51aeeec470f8e3eaddf71faf5e9a94c6246988d5..97d54757565ff6da62813f91407e7ea7e3e9b5a4 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -375,6 +375,7 @@ Orjan Johansen
 Fredrik Johansson
 Gregory K. Johnson
 Simon Johnston
+Thomas Jollans
 Evan Jones
 Jeremy Jones
 Richard Jones
index d8096409d9eb5217a6ba3a9c04837937aa905d2d..92a7c65641e07d3eb5e7940db4eb32b36d821628 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,9 @@ C-API
 Library
 -------
 
+- Issue #8897: Fix sunau module, use bytes to write the header. Patch written
+  by Thomas Jollans.
+
 - Issue #6470: Drop UNC prefix in FixTk.
 
 - Issue #4768: base64 encoded email body parts were incorrectly stored as