cpython: 6a599249e8b7 (original) (raw)

Mercurial > cpython

changeset 87148:6a599249e8b7

Issue #5202: Added support for unseekable files in the wave module. [#5202]

Serhiy Storchaka storchaka@gmail.com
date Sat, 16 Nov 2013 13:04:00 +0200
parents cc8e56886807
children b96f4ee1b08b
files Doc/library/wave.rst Lib/test/audiotests.py Lib/test/test_aifc.py Lib/wave.py Misc/NEWS
diffstat 5 files changed, 90 insertions(+), 34 deletions(-)[+] [-] Doc/library/wave.rst 10 Lib/test/audiotests.py 60 Lib/test/test_aifc.py 44 Lib/wave.py 8 Misc/NEWS 2

line wrap: on

line diff

--- a/Doc/library/wave.rst +++ b/Doc/library/wave.rst @@ -19,7 +19,7 @@ The :mod:wave module defines the follo .. function:: open(file, mode=None) If file is a string, open the file by that name, otherwise treat it as a

.. function:: openfp(file, mode) @@ -154,7 +156,8 @@ Wave_write objects, as returned by :func .. method:: Wave_write.close() Make sure nframes is correct, and close the file if it was opened by

.. method:: Wave_write.setnchannels(n) @@ -208,7 +211,8 @@ Wave_write objects, as returned by :func .. method:: Wave_write.writeframes(data)

Note that it is invalid to set any parameters after calling :meth:writeframes

--- a/Lib/test/audiotests.py +++ b/Lib/test/audiotests.py @@ -21,6 +21,13 @@ def byteswap4(data): a.byteswap() return a.tobytes() +class UnseekableIO(io.FileIO):

+

+ class AudioTests: close_fd = False @@ -177,6 +184,59 @@ class AudioWriteTests(AudioTests): self.assertEqual(testfile.read(13), b'ababagalamaga') self.check_file(testfile, self.nframes, self.frames)

+

+

+

+

+

+

+

+ class AudioTestsWithSourceFile(AudioTests):

--- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -8,10 +8,17 @@ import struct import aifc -class AifcPCM8Test(audiotests.AudioWriteTests,

+class AifcTest(audiotests.AudioWriteTests,

+ + +class AifcPCM8Test(AifcTest, unittest.TestCase): sndfilename = 'pluck-pcm8.aiff' sndfilenframes = 3307 nchannels = 2 @@ -26,13 +33,9 @@ class AifcPCM8Test(audiotests.AudioWrite 11FA 3EFB BCFC 66FF CF04 4309 C10E 5112 EE17 8216 7F14 8012 [](#l3.25) 490E 520D EF0F CE0F E40C 630A 080A 2B0B 510E 8B11 B60E 440A [](#l3.26) """)

-class AifcPCM16Test(audiotests.AudioWriteTests,

+class AifcPCM16Test(AifcTest, unittest.TestCase): sndfilename = 'pluck-pcm16.aiff' sndfilenframes = 3307 nchannels = 2 @@ -49,13 +52,9 @@ class AifcPCM16Test(audiotests.AudioWrit EEE21753 82071665 7FFF1443 8004128F 49A20EAF 52BB0DBA EFB40F60 CE3C0FBF [](#l3.40) E4B30CEC 63430A5C 08C80A20 2BBB0B08 514A0E43 8BCF1139 B6F60EEB 44120A5E [](#l3.41) """)

-class AifcPCM24Test(audiotests.AudioWriteTests,

+class AifcPCM24Test(AifcTest, unittest.TestCase): sndfilename = 'pluck-pcm24.aiff' sndfilenframes = 3307 nchannels = 2 @@ -78,13 +77,9 @@ class AifcPCM24Test(audiotests.AudioWrit E4B49C0CEA2D 6344A80A5A7C 08C8FE0A1FFE 2BB9860B0A0E [](#l3.55) 51486F0E44E1 8BCC64113B05 B6F4EC0EEB36 4413170A5B48 [](#l3.56) """)

-class AifcPCM32Test(audiotests.AudioWriteTests,

+class AifcPCM32Test(AifcTest, unittest.TestCase): sndfilename = 'pluck-pcm32.aiff' sndfilenframes = 3307 nchannels = 2 @@ -107,13 +102,9 @@ class AifcPCM32Test(audiotests.AudioWrit E4B49CC00CEA2D90 6344A8800A5A7CA0 08C8FE800A1FFEE0 2BB986C00B0A0E00 [](#l3.70) 51486F800E44E190 8BCC6480113B0580 B6F4EC000EEB3630 441317800A5B48A0 [](#l3.71) """)

-class AifcULAWTest(audiotests.AudioWriteTests,

+class AifcULAWTest(AifcTest, unittest.TestCase): sndfilename = 'pluck-ulaw.aifc' sndfilenframes = 3307 nchannels = 2 @@ -132,13 +123,9 @@ class AifcULAWTest(audiotests.AudioWrite """) if sys.byteorder != 'big': frames = audiotests.byteswap2(frames)

-class AifcALAWTest(audiotests.AudioWriteTests,

+class AifcALAWTest(AifcTest, unittest.TestCase): sndfilename = 'pluck-alaw.aifc' sndfilenframes = 3307 nchannels = 2 @@ -157,7 +144,6 @@ class AifcALAWTest(audiotests.AudioWrite """) if sys.byteorder != 'big': frames = audiotests.byteswap2(frames)

class AifcMiscTest(audiotests.AudioTests, unittest.TestCase):

--- a/Lib/wave.py +++ b/Lib/wave.py @@ -491,14 +491,18 @@ class Wave_write: if not self._nframes: self._nframes = initlength // (self._nchannels * self._sampwidth) self._datalength = self._nframes * self._nchannels * self._sampwidth

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -47,6 +47,8 @@ Core and Builtins Library ------- +- Issue #5202: Added support for unseekable files in the wave module. +