]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #1512791: In setframerate method of Wave_write, round non-integral
authorMark Dickinson <dickinsm@gmail.com>
Sat, 28 Aug 2010 17:22:16 +0000 (17:22 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sat, 28 Aug 2010 17:22:16 +0000 (17:22 +0000)
inputs to the nearest integer.  Thanks Neil Tallim for the patch.

Doc/library/wave.rst
Lib/test/test_wave.py
Lib/wave.py
Misc/ACKS
Misc/NEWS

index 794559b5a1e03329ffa24617799d077dcaac9adf..a79489c80346c921c6df060bc7b02e8a4c70f5e1 100644 (file)
@@ -157,6 +157,10 @@ Wave_write objects, as returned by :func:`.open`, have the following methods:
 
    Set the frame rate to *n*.
 
+   .. versionchanged:: 3.2
+      A non-integral input to this method is rounded to the nearest
+      integer.
+
 
 .. method:: Wave_write.setnframes(n)
 
index 1bcaa242c01864e466d3b0447176dd539ff26d54..e0aace495c861a5a7e62258af938e5b62ae0901b 100644 (file)
@@ -22,11 +22,14 @@ class TestWave(unittest.TestCase):
         except OSError:
             pass
 
-    def test_it(self):
+    def test_it(self, test_rounding=False):
         self.f = wave.open(TESTFN, 'wb')
         self.f.setnchannels(nchannels)
         self.f.setsampwidth(sampwidth)
-        self.f.setframerate(framerate)
+        if test_rounding:
+            self.f.setframerate(framerate - 0.1)
+        else:
+            self.f.setframerate(framerate)
         self.f.setnframes(nframes)
         output = b'\0' * nframes * nchannels * sampwidth
         self.f.writeframes(output)
@@ -39,6 +42,13 @@ class TestWave(unittest.TestCase):
         self.assertEqual(nframes, self.f.getnframes())
         self.assertEqual(self.f.readframes(nframes), output)
 
+    def test_fractional_framerate(self):
+        """
+        Addresses [ 1512791 ] module wave does no rounding
+        Floating point framerates should be rounded, rather than truncated.
+        """
+        self.test_it(test_rounding=True)
+
     def test_issue7681(self):
         self.f = wave.open(TESTFN, 'wb')
         self.f.setnchannels(nchannels)
index 2fa9b6b11fb1ac116c34f12042572cecf3be3c76..950d8e2ff25628e7df8a95b29871f1f08234d680 100644 (file)
@@ -355,7 +355,7 @@ class Wave_write:
             raise Error('cannot change parameters after starting to write')
         if framerate <= 0:
             raise Error('bad frame rate')
-        self._framerate = framerate
+        self._framerate = int(round(framerate))
 
     def getframerate(self):
         if not self._framerate:
index ef92941d881842b1d510e7bc7f8206ad92076919..0ab67dda60db3b0b94033cdbc0dd0752a3ef787c 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -792,6 +792,7 @@ Paul Swartz
 Thenault Sylvain
 Péter Szabó
 Arfrever Frehtes Taifersar Arahesis
+Neil Tallim
 Geoff Talvola
 Musashi Tamura
 William Tanksley
index 7ef147d22ce82c8b1aeb70d5bb120f64fc38b39f..1179c9f83de81705aea5cb29f1d8ee9be2b8af8c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -132,6 +132,9 @@ Extensions
 Library
 -------
 
+- Issue #1512791: In setframerate() in the wave module, non-integral
+  frame rates are rounded to the nearest integer.
+
 - Issue #8797: urllib2 does a retry for Basic Authentication failure instead of
   falling into recursion.