Issue #9243: Fix sndhdr module and add unit tests, contributed by James Lee.
diff --git a/Lib/test/sndhdrdata/README b/Lib/test/sndhdrdata/README
new file mode 100644
index 0000000..8a17c00
--- /dev/null
+++ b/Lib/test/sndhdrdata/README
@@ -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>
+
diff --git a/Lib/test/sndhdrdata/sndhdr.8svx b/Lib/test/sndhdrdata/sndhdr.8svx
new file mode 100644
index 0000000..8cd6cde
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.8svx
Binary files differ
diff --git a/Lib/test/sndhdrdata/sndhdr.aifc b/Lib/test/sndhdrdata/sndhdr.aifc
new file mode 100644
index 0000000..8aae4e7
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.aifc
Binary files differ
diff --git a/Lib/test/sndhdrdata/sndhdr.aiff b/Lib/test/sndhdrdata/sndhdr.aiff
new file mode 100644
index 0000000..8c279a7
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.aiff
Binary files differ
diff --git a/Lib/test/sndhdrdata/sndhdr.au b/Lib/test/sndhdrdata/sndhdr.au
new file mode 100644
index 0000000..67c9e8f
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.au
Binary files differ
diff --git a/Lib/test/sndhdrdata/sndhdr.hcom b/Lib/test/sndhdrdata/sndhdr.hcom
new file mode 100644
index 0000000..debb02d
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.hcom
Binary files differ
diff --git a/Lib/test/sndhdrdata/sndhdr.sndt b/Lib/test/sndhdrdata/sndhdr.sndt
new file mode 100644
index 0000000..e1ca9cb
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.sndt
Binary files differ
diff --git a/Lib/test/sndhdrdata/sndhdr.voc b/Lib/test/sndhdrdata/sndhdr.voc
new file mode 100644
index 0000000..53a91fd
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.voc
Binary files differ
diff --git a/Lib/test/sndhdrdata/sndhdr.wav b/Lib/test/sndhdrdata/sndhdr.wav
new file mode 100644
index 0000000..0dca367
--- /dev/null
+++ b/Lib/test/sndhdrdata/sndhdr.wav
Binary files differ
diff --git a/Lib/test/test_sndhdr.py b/Lib/test/test_sndhdr.py
new file mode 100644
index 0000000..4b4c857
--- /dev/null
+++ b/Lib/test/test_sndhdr.py
@@ -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()