Issue #9243: Fix sndhdr module and add unit tests, contributed by James Lee.

This commit is contained in:
Victor Stinner 2010-07-13 23:04:56 +00:00
parent 903396ee66
commit e9ebde48cf
13 changed files with 66 additions and 4 deletions

View file

@ -57,12 +57,12 @@ tests = []
def test_aifc(h, f): def test_aifc(h, f):
import aifc import aifc
if h.startswith(b'FORM'): if not h.startswith(b'FORM'):
return None return None
if h[8:12] == b'AIFC': if h[8:12] == b'AIFC':
fmt = 'aifc' fmt = 'aifc'
elif h[8:12] == b'AIFF': elif h[8:12] == b'AIFF':
fmt = b'aiff' fmt = 'aiff'
else: else:
return None return None
f.seek(0) f.seek(0)
@ -123,7 +123,7 @@ tests.append(test_hcom)
def test_voc(h, f): def test_voc(h, f):
if h.startswith(b'Creative Voice File\032'): if not h.startswith(b'Creative Voice File\032'):
return None return None
sbseek = get_short_le(h[20:22]) sbseek = get_short_le(h[20:22])
rate = 0 rate = 0
@ -150,7 +150,7 @@ tests.append(test_wav)
def test_8svx(h, f): def test_8svx(h, f):
if h.startswith(b'FORM') or h[8:12] != b'8SVX': if not h.startswith(b'FORM') or h[8:12] != b'8SVX':
return None return None
# Should decode it to get #channels -- assume always 1 # Should decode it to get #channels -- assume always 1
return '8svx', 0, 1, 0, 8 return '8svx', 0, 1, 0, 8

View file

@ -0,0 +1,12 @@
Sound file samples used by Lib/test/test_sndhdr.py and generated using the
following commands:
dd if=/dev/zero of=sndhdr.raw bs=20 count=1
sox -s -2 -c 2 -r 44100 sndhdr.raw sndhdr.<format>
Sound file samples used by Lib/test/test_sndhdr.py and generated using the
following commands:
dd if=/dev/zero of=sndhdr.raw bs=20 count=1
sox -s -2 -c 2 -r 44100 sndhdr.raw sndhdr.<format>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

47
Lib/test/test_sndhdr.py Normal file
View file

@ -0,0 +1,47 @@
import sndhdr
import unittest
from test.support import findfile
class TestFormats(unittest.TestCase):
def test_data(self):
for filename, expected in (
('sndhdr.8svx', ('8svx', 0, 1, 0, 8)),
('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)),
('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)),
('sndhdr.au', ('au', 44100, 2, 5.0, 16)),
('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)),
('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)),
('sndhdr.voc', ('voc', 0, 1, -1, 8)),
('sndhdr.wav', ('wav', 44100, 2, -1, 16)),
):
filename = findfile(filename, subdir="sndhdrdata")
what = sndhdr.what(filename)
self.assertNotEqual(what, None, filename)
self.assertSequenceEqual(what, expected)
if __name__ == '__main__':
unittest.main()
import sndhdr
import unittest
from test.support import findfile
class TestFormats(unittest.TestCase):
def test_data(self):
for filename, expected in (
('sndhdr.8svx', ('8svx', 0, 1, 0, 8)),
('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)),
('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)),
('sndhdr.au', ('au', 44100, 2, 5.0, 16)),
('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)),
('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)),
('sndhdr.voc', ('voc', 0, 1, -1, 8)),
('sndhdr.wav', ('wav', 44100, 2, -1, 16)),
):
filename = findfile(filename, subdir="sndhdrdata")
what = sndhdr.what(filename)
self.assertNotEqual(what, None, filename)
self.assertSequenceEqual(what, expected)
if __name__ == '__main__':
unittest.main()

View file

@ -454,6 +454,7 @@ Ben Laurie
Simon Law Simon Law
Chris Lawrence Chris Lawrence
Brian Leair Brian Leair
James Lee
John J. Lee John J. Lee
Inyeol Lee Inyeol Lee
Thomas Lee Thomas Lee

View file

@ -473,6 +473,8 @@ C-API
Library Library
------- -------
- Issue #9243: Fix sndhdr module and add unit tests, contributed by James Lee.
- ``ast.literal_eval()`` now allows byte literals. - ``ast.literal_eval()`` now allows byte literals.
- Issue #9137: Fix issue in MutableMapping.update, which incorrectly - Issue #9137: Fix issue in MutableMapping.update, which incorrectly