summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-08-24 18:46:27 (GMT)
committerGeorg Brandl <georg@python.org>2007-08-24 18:46:27 (GMT)
commitfe3b4b9507368de10a0b16aada418b08e0108c3b (patch)
tree23fb8f9f6d3ad45cffc36af3592b9d0bf1cfed8f /Lib
parente7445de2b1c72fe8fa7310b629e0d2982eb46b65 (diff)
downloadcpython-fe3b4b9507368de10a0b16aada418b08e0108c3b.zip
cpython-fe3b4b9507368de10a0b16aada418b08e0108c3b.tar.gz
cpython-fe3b4b9507368de10a0b16aada418b08e0108c3b.tar.bz2
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/output/test_linuxaudiodev7
-rw-r--r--Lib/test/test_linuxaudiodev.py144
-rw-r--r--Lib/test/test_ossaudiodev.py3
3 files changed, 78 insertions, 76 deletions
diff --git a/Lib/test/output/test_linuxaudiodev b/Lib/test/output/test_linuxaudiodev
deleted file mode 100644
index 3e8c691..0000000
--- a/Lib/test/output/test_linuxaudiodev
+++ /dev/null
@@ -1,7 +0,0 @@
-test_linuxaudiodev
-expected rate >= 0, not -1
-expected sample size >= 0, not -2
-nchannels must be 1 or 2, not 3
-unknown audio encoding: 177
-for linear unsigned 16-bit little-endian audio, expected sample size 16, not 8
-for linear unsigned 8-bit audio, expected sample size 8, not 16
diff --git a/Lib/test/test_linuxaudiodev.py b/Lib/test/test_linuxaudiodev.py
index fe902b5..d884cf8 100644
--- a/Lib/test/test_linuxaudiodev.py
+++ b/Lib/test/test_linuxaudiodev.py
@@ -1,7 +1,7 @@
from test import test_support
test_support.requires('audio')
-from test.test_support import verbose, findfile, TestFailed, TestSkipped
+from test.test_support import findfile, TestSkipped, run_unittest
import errno
import fcntl
@@ -12,81 +12,91 @@ import select
import sunaudio
import time
import audioop
+import unittest
SND_FORMAT_MULAW_8 = 1
-def play_sound_file(path):
- fp = open(path, 'r')
- size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
- data = fp.read()
- fp.close()
+class LinuxAudioDevTests(unittest.TestCase):
- if enc != SND_FORMAT_MULAW_8:
- print "Expect .au file with 8-bit mu-law samples"
- return
+ def setUp(self):
+ self.dev = linuxaudiodev.open('w')
- try:
- a = linuxaudiodev.open('w')
- except linuxaudiodev.error, msg:
- if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
- raise TestSkipped, msg
- raise TestFailed, msg
+ def tearDown(self):
+ self.dev.close()
- # convert the data to 16-bit signed
- data = audioop.ulaw2lin(data, 2)
+ def test_methods(self):
+ # at least check that these methods can be invoked
+ self.dev.bufsize()
+ self.dev.obufcount()
+ self.dev.obuffree()
+ self.dev.getptr()
+ self.dev.fileno()
- # set the data format
- if sys.byteorder == 'little':
- fmt = linuxaudiodev.AFMT_S16_LE
- else:
- fmt = linuxaudiodev.AFMT_S16_BE
+ def test_play_sound_file(self):
+ path = findfile("audiotest.au")
+ fp = open(path, 'r')
+ size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
+ data = fp.read()
+ fp.close()
- # at least check that these methods can be invoked
- a.bufsize()
- a.obufcount()
- a.obuffree()
- a.getptr()
- a.fileno()
+ if enc != SND_FORMAT_MULAW_8:
+ self.fail("Expect .au file with 8-bit mu-law samples")
- # set parameters based on .au file headers
- a.setparameters(rate, 16, nchannels, fmt)
- a.write(data)
- a.flush()
- a.close()
+ # convert the data to 16-bit signed
+ data = audioop.ulaw2lin(data, 2)
-def test_errors():
- a = linuxaudiodev.open("w")
- size = 8
- fmt = linuxaudiodev.AFMT_U8
- rate = 8000
- nchannels = 1
- try:
- a.setparameters(-1, size, nchannels, fmt)
- except ValueError, msg:
- print msg
- try:
- a.setparameters(rate, -2, nchannels, fmt)
- except ValueError, msg:
- print msg
- try:
- a.setparameters(rate, size, 3, fmt)
- except ValueError, msg:
- print msg
- try:
- a.setparameters(rate, size, nchannels, 177)
- except ValueError, msg:
- print msg
- try:
- a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE)
- except ValueError, msg:
- print msg
- try:
- a.setparameters(rate, 16, nchannels, fmt)
- except ValueError, msg:
- print msg
+ # set the data format
+ if sys.byteorder == 'little':
+ fmt = linuxaudiodev.AFMT_S16_LE
+ else:
+ fmt = linuxaudiodev.AFMT_S16_BE
+
+ # set parameters based on .au file headers
+ self.dev.setparameters(rate, 16, nchannels, fmt)
+ self.dev.write(data)
+ self.dev.flush()
-def test():
- play_sound_file(findfile('audiotest.au'))
- test_errors()
+ def test_errors(self):
+ size = 8
+ fmt = linuxaudiodev.AFMT_U8
+ rate = 8000
+ nchannels = 1
+ try:
+ self.dev.setparameters(-1, size, nchannels, fmt)
+ except ValueError, err:
+ self.assertEquals(err.args[0], "expected rate >= 0, not -1")
+ try:
+ self.dev.setparameters(rate, -2, nchannels, fmt)
+ except ValueError, err:
+ self.assertEquals(err.args[0], "expected sample size >= 0, not -2")
+ try:
+ self.dev.setparameters(rate, size, 3, fmt)
+ except ValueError, err:
+ self.assertEquals(err.args[0], "nchannels must be 1 or 2, not 3")
+ try:
+ self.dev.setparameters(rate, size, nchannels, 177)
+ except ValueError, err:
+ self.assertEquals(err.args[0], "unknown audio encoding: 177")
+ try:
+ self.dev.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE)
+ except ValueError, err:
+ self.assertEquals(err.args[0], "for linear unsigned 16-bit little-endian "
+ "audio, expected sample size 16, not 8")
+ try:
+ self.dev.setparameters(rate, 16, nchannels, fmt)
+ except ValueError, err:
+ self.assertEquals(err.args[0], "for linear unsigned 8-bit audio, expected "
+ "sample size 8, not 16")
+
+def test_main():
+ try:
+ dsp = linuxaudiodev.open('w')
+ except IOError, msg:
+ if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
+ raise TestSkipped(msg)
+ raise
+ dsp.close()
+ run_unittest(LinuxAudioDevTests)
-test()
+if __name__ == '__main__':
+ test_main()
diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py
index 3fb5d6d..5a6c893 100644
--- a/Lib/test/test_ossaudiodev.py
+++ b/Lib/test/test_ossaudiodev.py
@@ -166,8 +166,7 @@ def test_main():
if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY):
raise TestSkipped(msg)
raise
- finally:
- dsp.close()
+ dsp.close()
test_support.run_unittest(__name__)
if __name__ == "__main__":