[Python-checkins] r82856 - in python/branches/py3k: Lib/sndhdr.py Lib/test/sndhdrdata Lib/test/sndhdrdata/README Lib/test/sndhdrdata/sndhdr.8svx Lib/test/sndhdrdata/sndhdr.aifc Lib/test/sndhdrdata/sndhdr.aiff Lib/test/sndhdrdata/sndhdr.au Lib/test/sndhdrdata/sndhdr.hcom Lib/test/sndhdrdata/sndhdr.sndt Lib/test/sndhdrdata/sndhdr.voc Lib/test/sndhdrdata/sndhdr.wav Lib/test/test_sndhdr.py Misc/ACKS Misc/NEWS

victor.stinner python-checkins at python.org
Wed Jul 14 01:04:56 CEST 2010


Author: victor.stinner
Date: Wed Jul 14 01:04:56 2010
New Revision: 82856

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


Added:
   python/branches/py3k/Lib/test/sndhdrdata/
   python/branches/py3k/Lib/test/sndhdrdata/README
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.8svx   (contents, props changed)
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.aifc   (contents, props changed)
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.aiff   (contents, props changed)
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.au   (contents, props changed)
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.hcom   (contents, props changed)
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.sndt   (contents, props changed)
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.voc   (contents, props changed)
   python/branches/py3k/Lib/test/sndhdrdata/sndhdr.wav   (contents, props changed)
   python/branches/py3k/Lib/test/test_sndhdr.py
Modified:
   python/branches/py3k/Lib/sndhdr.py
   python/branches/py3k/Misc/ACKS
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/sndhdr.py
==============================================================================
--- python/branches/py3k/Lib/sndhdr.py	(original)
+++ python/branches/py3k/Lib/sndhdr.py	Wed Jul 14 01:04:56 2010
@@ -57,12 +57,12 @@
 
 def test_aifc(h, f):
     import aifc
-    if h.startswith(b'FORM'):
+    if not h.startswith(b'FORM'):
         return None
     if h[8:12] == b'AIFC':
         fmt = 'aifc'
     elif h[8:12] == b'AIFF':
-        fmt = b'aiff'
+        fmt = 'aiff'
     else:
         return None
     f.seek(0)
@@ -123,7 +123,7 @@
 
 
 def test_voc(h, f):
-    if h.startswith(b'Creative Voice File\032'):
+    if not h.startswith(b'Creative Voice File\032'):
         return None
     sbseek = get_short_le(h[20:22])
     rate = 0
@@ -150,7 +150,7 @@
 
 
 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
     # Should decode it to get #channels -- assume always 1
     return '8svx', 0, 1, 0, 8

Added: python/branches/py3k/Lib/test/sndhdrdata/README
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/sndhdrdata/README	Wed Jul 14 01:04:56 2010
@@ -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>
+

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.8svx
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.aifc
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.aiff
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.au
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.hcom
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.sndt
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.voc
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/sndhdrdata/sndhdr.wav
==============================================================================
Binary file. No diff available.

Added: python/branches/py3k/Lib/test/test_sndhdr.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/test_sndhdr.py	Wed Jul 14 01:04:56 2010
@@ -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()

Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS	(original)
+++ python/branches/py3k/Misc/ACKS	Wed Jul 14 01:04:56 2010
@@ -454,6 +454,7 @@
 Simon Law
 Chris Lawrence
 Brian Leair
+James Lee
 John J. Lee
 Inyeol Lee
 Thomas Lee

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Wed Jul 14 01:04:56 2010
@@ -473,6 +473,8 @@
 Library
 -------
 
+- Issue #9243: Fix sndhdr module and add unit tests, contributed by James Lee.
+
 - ``ast.literal_eval()`` now allows byte literals.
 
 - Issue #9137: Fix issue in MutableMapping.update, which incorrectly


More information about the Python-checkins mailing list