summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_audioop.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-07-02 20:22:54 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-07-02 20:22:54 (GMT)
commit4118174315f4cba03208886af868fe31f1cd5b9d (patch)
tree9c06a3317ab82fbce405303931226e6cb3e6fbdb /Lib/test/test_audioop.py
parent200ff1853b43a0f0c907705ca8250ffe2539ba77 (diff)
downloadcpython-4118174315f4cba03208886af868fe31f1cd5b9d.zip
cpython-4118174315f4cba03208886af868fe31f1cd5b9d.tar.gz
cpython-4118174315f4cba03208886af868fe31f1cd5b9d.tar.bz2
Merged revisions 64475,64544-64545,64550,64557-64558,64565,64570,64577,64582-64583,64585,64590,64592-64593,64625,64630,64638,64647,64655-64656,64663-64664 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r64475 | raymond.hettinger | 2008-06-22 22:29:28 -0500 (Sun, 22 Jun 2008) | 1 line Issue 3161: Missing import and test. ........ r64544 | georg.brandl | 2008-06-26 16:12:55 -0500 (Thu, 26 Jun 2008) | 2 lines Use newer versions of externals. ........ r64545 | benjamin.peterson | 2008-06-26 16:23:30 -0500 (Thu, 26 Jun 2008) | 1 line add a htmlview directive ........ r64550 | brett.cannon | 2008-06-26 19:32:16 -0500 (Thu, 26 Jun 2008) | 2 lines Ignore .pyc and .pyo files. ........ r64557 | mark.dickinson | 2008-06-27 05:11:52 -0500 (Fri, 27 Jun 2008) | 3 lines Remove trailing 'L's from numerator and denominator in the repr() of a Fraction instance. ........ r64558 | mark.dickinson | 2008-06-27 06:03:21 -0500 (Fri, 27 Jun 2008) | 2 lines Add Jean Brouwers for his work on math.sum ........ r64565 | raymond.hettinger | 2008-06-27 16:34:24 -0500 (Fri, 27 Jun 2008) | 1 line Fix whitespace in example code. ........ r64570 | hyeshik.chang | 2008-06-27 20:04:31 -0500 (Fri, 27 Jun 2008) | 8 lines Give information for compililation of _multiprocessing.SemLock on FreeBSD: FreeBSD's P1003.1b semaphore support is highly experimental and it's disabled by default. Even if a user loads the experimental kernel module manually, _multiprocessing doesn't work correctly due to several known incompatibilities around sem_unlink and sem_getvalue, yet. ........ r64577 | raymond.hettinger | 2008-06-28 17:16:53 -0500 (Sat, 28 Jun 2008) | 1 line Issue 3230: Do not the set specific size macro. ........ r64582 | benjamin.peterson | 2008-06-28 18:06:05 -0500 (Sat, 28 Jun 2008) | 2 lines convert test_audioop to unittest. Thanks to Giampaolo Rodola. ........ r64583 | benjamin.peterson | 2008-06-28 18:06:49 -0500 (Sat, 28 Jun 2008) | 1 line rewrap ........ r64585 | benjamin.peterson | 2008-06-28 18:35:31 -0500 (Sat, 28 Jun 2008) | 1 line fix typo ........ r64590 | benjamin.peterson | 2008-06-29 08:43:07 -0500 (Sun, 29 Jun 2008) | 1 line reinstate the ending backtick. thanks Nick :) ........ r64592 | vinay.sajip | 2008-06-29 16:25:28 -0500 (Sun, 29 Jun 2008) | 2 lines Removed out-of-date comment in _install_handlers and used issubclass in place of equality comparison of classes. ........ r64593 | vinay.sajip | 2008-06-29 16:27:15 -0500 (Sun, 29 Jun 2008) | 1 line Updated to reflect change in logging.config to remove out-of-date comment in _install_handlers and the use of issubclass in place of equality comparison of classes. ........ r64625 | georg.brandl | 2008-07-01 14:59:00 -0500 (Tue, 01 Jul 2008) | 2 lines Add a link to PEP 324. ........ r64630 | georg.brandl | 2008-07-01 15:18:10 -0500 (Tue, 01 Jul 2008) | 2 lines #3216: fix Execute's parameter description. ........ r64638 | georg.brandl | 2008-07-01 15:50:02 -0500 (Tue, 01 Jul 2008) | 2 lines #1410739: add a footnote about "is" and "unusual" behavior. ........ r64647 | benjamin.peterson | 2008-07-01 18:33:06 -0500 (Tue, 01 Jul 2008) | 1 line add ABC to the glossary ........ r64655 | mark.dickinson | 2008-07-02 04:37:01 -0500 (Wed, 02 Jul 2008) | 7 lines Replace occurrences of '\d' with '[0-9]' in Decimal regex, to make sure that the behaviour of Decimal doesn't change if/when re.UNICODE becomes assumed in Python 3.0. Also add a check that alternative Unicode digits (e.g. u'\N{FULLWIDTH DIGIT ONE}') are *not* accepted in a numeric string. ........ r64656 | nick.coghlan | 2008-07-02 08:09:19 -0500 (Wed, 02 Jul 2008) | 1 line Issue 3190: pydoc now hides module __package__ attributes ........ r64663 | jesse.noller | 2008-07-02 11:44:09 -0500 (Wed, 02 Jul 2008) | 1 line Reenable the manager tests with Amaury's threading fix ........ r64664 | facundo.batista | 2008-07-02 11:52:55 -0500 (Wed, 02 Jul 2008) | 4 lines Issue #449227: Now with the rlcompleter module, callable objects are added a '(' when completed. ........
Diffstat (limited to 'Lib/test/test_audioop.py')
-rw-r--r--Lib/test/test_audioop.py415
1 files changed, 149 insertions, 266 deletions
diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py
index ae796ba..d43159a 100644
--- a/Lib/test/test_audioop.py
+++ b/Lib/test/test_audioop.py
@@ -1,288 +1,171 @@
-# Test audioop.
import audioop
-from test.support import verbose
+import unittest
+from test.support import run_unittest
+
def gendata1():
return b'\0\1\2'
def gendata2():
- if verbose:
- print('getsample')
if audioop.getsample(b'\0\1', 2, 0) == 1:
return b'\0\0\0\1\0\2'
else:
return b'\0\0\1\0\2\0'
def gendata4():
- if verbose:
- print('getsample')
if audioop.getsample(b'\0\0\0\1', 4, 0) == 1:
return b'\0\0\0\0\0\0\0\1\0\0\0\2'
else:
return b'\0\0\0\0\1\0\0\0\2\0\0\0'
-def testmax(data):
- if verbose:
- print('max')
- if audioop.max(data[0], 1) != 2 or \
- audioop.max(data[1], 2) != 2 or \
- audioop.max(data[2], 4) != 2:
- return 0
- return 1
-
-def testminmax(data):
- if verbose:
- print('minmax')
- if audioop.minmax(data[0], 1) != (0, 2) or \
- audioop.minmax(data[1], 2) != (0, 2) or \
- audioop.minmax(data[2], 4) != (0, 2):
- return 0
- return 1
-
-def testmaxpp(data):
- if verbose:
- print('maxpp')
- if audioop.maxpp(data[0], 1) != 0 or \
- audioop.maxpp(data[1], 2) != 0 or \
- audioop.maxpp(data[2], 4) != 0:
- return 0
- return 1
-
-def testavg(data):
- if verbose:
- print('avg')
- if audioop.avg(data[0], 1) != 1 or \
- audioop.avg(data[1], 2) != 1 or \
- audioop.avg(data[2], 4) != 1:
- return 0
- return 1
-
-def testavgpp(data):
- if verbose:
- print('avgpp')
- if audioop.avgpp(data[0], 1) != 0 or \
- audioop.avgpp(data[1], 2) != 0 or \
- audioop.avgpp(data[2], 4) != 0:
- return 0
- return 1
-
-def testrms(data):
- if audioop.rms(data[0], 1) != 1 or \
- audioop.rms(data[1], 2) != 1 or \
- audioop.rms(data[2], 4) != 1:
- return 0
- return 1
-
-def testcross(data):
- if verbose:
- print('cross')
- if audioop.cross(data[0], 1) != 0 or \
- audioop.cross(data[1], 2) != 0 or \
- audioop.cross(data[2], 4) != 0:
- return 0
- return 1
-
-def testadd(data):
- if verbose:
- print('add')
- data2 = []
- for d in data:
- str = bytearray(len(d))
- for i,b in enumerate(d):
- str[i] = 2*b
- data2.append(str)
- if audioop.add(data[0], data[0], 1) != data2[0] or \
- audioop.add(data[1], data[1], 2) != data2[1] or \
- audioop.add(data[2], data[2], 4) != data2[2]:
- return 0
- return 1
-
-def testbias(data):
- if verbose:
- print('bias')
- # Note: this test assumes that avg() works
- d1 = audioop.bias(data[0], 1, 100)
- d2 = audioop.bias(data[1], 2, 100)
- d4 = audioop.bias(data[2], 4, 100)
- if audioop.avg(d1, 1) != 101 or \
- audioop.avg(d2, 2) != 101 or \
- audioop.avg(d4, 4) != 101:
- return 0
- return 1
-
-def testlin2lin(data):
- if verbose:
- print('lin2lin')
- # too simple: we test only the size
- for d1 in data:
- for d2 in data:
- got = len(d1)//3
- wtd = len(d2)//3
- if len(audioop.lin2lin(d1, got, wtd)) != len(d2):
- return 0
- return 1
-
-def testadpcm2lin(data):
- # Very cursory test
- if audioop.adpcm2lin(b'\0\0', 1, None) != (b'\0\0\0\0', (0,0)):
- return 0
- return 1
-
-def testlin2adpcm(data):
- if verbose:
- print('lin2adpcm')
- # Very cursory test
- if audioop.lin2adpcm(b'\0\0\0\0', 1, None) != (b'\0\0', (0,0)):
- return 0
- return 1
-
-def testlin2alaw(data):
- if verbose:
- print('lin2alaw')
- if audioop.lin2alaw(data[0], 1) != b'\xd5\xc5\xf5' or \
- audioop.lin2alaw(data[1], 2) != b'\xd5\xd5\xd5' or \
- audioop.lin2alaw(data[2], 4) != b'\xd5\xd5\xd5':
- return 0
- return 1
-
-def testalaw2lin(data):
- if verbose:
- print('alaw2lin')
- # Cursory
- d = audioop.lin2alaw(data[0], 1)
- if audioop.alaw2lin(d, 1) != data[0]:
- return 0
- return 1
-
-def testlin2ulaw(data):
- if verbose:
- print('lin2ulaw')
- if audioop.lin2ulaw(data[0], 1) != b'\xff\xe7\xdb' or \
- audioop.lin2ulaw(data[1], 2) != b'\xff\xff\xff' or \
- audioop.lin2ulaw(data[2], 4) != b'\xff\xff\xff':
- return 0
- return 1
-
-def testulaw2lin(data):
- if verbose:
- print('ulaw2lin')
- # Cursory
- d = audioop.lin2ulaw(data[0], 1)
- if audioop.ulaw2lin(d, 1) != data[0]:
- return 0
- return 1
-
-def testmul(data):
- if verbose:
- print('mul')
- data2 = []
- for d in data:
- str = bytearray(len(d))
- for i,b in enumerate(d):
- str[i] = 2*b
- data2.append(str)
- if audioop.mul(data[0], 1, 2) != data2[0] or \
- audioop.mul(data[1],2, 2) != data2[1] or \
- audioop.mul(data[2], 4, 2) != data2[2]:
- return 0
- return 1
-
-def testratecv(data):
- if verbose:
- print('ratecv')
- state = None
- d1, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
- d2, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
- if d1 + d2 != b'\000\000\001\001\002\001\000\000\001\001\002':
- return 0
- return 1
-
-def testreverse(data):
- if verbose:
- print('reverse')
- if audioop.reverse(data[0], 1) != b'\2\1\0':
- return 0
- return 1
-
-def testtomono(data):
- if verbose:
- print('tomono')
- data2 = bytearray()
- for d in data[0]:
- data2.append(d)
- data2.append(d)
- if audioop.tomono(data2, 1, 0.5, 0.5) != data[0]:
- return 0
- return 1
-
-def testtostereo(data):
- if verbose:
- print('tostereo')
- data2 = bytearray()
- for d in data[0]:
- data2.append(d)
- data2.append(d)
- if audioop.tostereo(data[0], 1, 1, 1) != data2:
- return 0
- return 1
-
-def testfindfactor(data):
- if verbose:
- print('findfactor')
- if audioop.findfactor(data[1], data[1]) != 1.0:
- return 0
- return 1
-
-def testfindfit(data):
- if verbose:
- print('findfit')
- if audioop.findfit(data[1], data[1]) != (0, 1.0):
- return 0
- return 1
-
-def testfindmax(data):
- if verbose:
- print('findmax')
- if audioop.findmax(data[1], 1) != 2:
- return 0
- return 1
-
-def testgetsample(data):
- if verbose:
- print('getsample')
- for i in range(3):
- if audioop.getsample(data[0], 1, i) != i or \
- audioop.getsample(data[1], 2, i) != i or \
- audioop.getsample(data[2], 4, i) != i:
- return 0
- return 1
-
-def testone(name, data):
- try:
- func = eval('test'+name)
- except NameError:
- print('No test found for audioop.'+name+'()')
- return
- try:
- rv = func(data)
- except Exception as e:
- print('Test FAILED for audioop.'+name+'() (with %s)' % repr(e))
- return
- if not rv:
- print('Test FAILED for audioop.'+name+'()')
-
-def test_main():
- data = [gendata1(), gendata2(), gendata4()]
- names = dir(audioop)
- # We know there is a routine 'add'
- routines = []
- for n in names:
- if type(eval('audioop.'+n)) == type(audioop.add):
- routines.append(n)
- for n in routines:
- testone(n, data)
+data = [gendata1(), gendata2(), gendata4()]
+
+
+class TestAudioop(unittest.TestCase):
+
+ def test_max(self):
+ self.assertEqual(audioop.max(data[0], 1), 2)
+ self.assertEqual(audioop.max(data[1], 2), 2)
+ self.assertEqual(audioop.max(data[2], 4), 2)
+
+ def test_minmax(self):
+ self.assertEqual(audioop.minmax(data[0], 1), (0, 2))
+ self.assertEqual(audioop.minmax(data[1], 2), (0, 2))
+ self.assertEqual(audioop.minmax(data[2], 4), (0, 2))
+
+ def test_maxpp(self):
+ self.assertEqual(audioop.maxpp(data[0], 1), 0)
+ self.assertEqual(audioop.maxpp(data[1], 2), 0)
+ self.assertEqual(audioop.maxpp(data[2], 4), 0)
+
+ def test_avg(self):
+ self.assertEqual(audioop.avg(data[0], 1), 1)
+ self.assertEqual(audioop.avg(data[1], 2), 1)
+ self.assertEqual(audioop.avg(data[2], 4), 1)
+
+ def test_avgpp(self):
+ self.assertEqual(audioop.avgpp(data[0], 1), 0)
+ self.assertEqual(audioop.avgpp(data[1], 2), 0)
+ self.assertEqual(audioop.avgpp(data[2], 4), 0)
+
+ def test_rms(self):
+ self.assertEqual(audioop.rms(data[0], 1), 1)
+ self.assertEqual(audioop.rms(data[1], 2), 1)
+ self.assertEqual(audioop.rms(data[2], 4), 1)
+
+ def test_cross(self):
+ self.assertEqual(audioop.cross(data[0], 1), 0)
+ self.assertEqual(audioop.cross(data[1], 2), 0)
+ self.assertEqual(audioop.cross(data[2], 4), 0)
+
+ def test_add(self):
+ data2 = []
+ for d in data:
+ str = bytearray(len(d))
+ for i,b in enumerate(d):
+ str[i] = 2*b
+ data2.append(str)
+ self.assertEqual(audioop.add(data[0], data[0], 1), data2[0])
+ self.assertEqual(audioop.add(data[1], data[1], 2), data2[1])
+ self.assertEqual(audioop.add(data[2], data[2], 4), data2[2])
+
+ def test_bias(self):
+ # Note: this test assumes that avg() works
+ d1 = audioop.bias(data[0], 1, 100)
+ d2 = audioop.bias(data[1], 2, 100)
+ d4 = audioop.bias(data[2], 4, 100)
+ self.assertEqual(audioop.avg(d1, 1), 101)
+ self.assertEqual(audioop.avg(d2, 2), 101)
+ self.assertEqual(audioop.avg(d4, 4), 101)
+
+ def test_lin2lin(self):
+ # too simple: we test only the size
+ for d1 in data:
+ for d2 in data:
+ got = len(d1)//3
+ wtd = len(d2)//3
+ self.assertEqual(len(audioop.lin2lin(d1, got, wtd)), len(d2))
+
+ def test_adpcm2lin(self):
+ # Very cursory test
+ self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0\0\0\0', (0,0)))
+
+ def test_lin2adpcm(self):
+ # Very cursory test
+ self.assertEqual(audioop.lin2adpcm(b'\0\0\0\0', 1, None), (b'\0\0', (0,0)))
+
+ def test_lin2alaw(self):
+ self.assertEqual(audioop.lin2alaw(data[0], 1), b'\xd5\xc5\xf5')
+ self.assertEqual(audioop.lin2alaw(data[1], 2), b'\xd5\xd5\xd5')
+ self.assertEqual(audioop.lin2alaw(data[2], 4), b'\xd5\xd5\xd5')
+
+ def test_alaw2lin(self):
+ # Cursory
+ d = audioop.lin2alaw(data[0], 1)
+ self.assertEqual(audioop.alaw2lin(d, 1), data[0])
+
+ def test_lin2ulaw(self):
+ self.assertEqual(audioop.lin2ulaw(data[0], 1), b'\xff\xe7\xdb')
+ self.assertEqual(audioop.lin2ulaw(data[1], 2), b'\xff\xff\xff')
+ self.assertEqual(audioop.lin2ulaw(data[2], 4), b'\xff\xff\xff')
+
+ def test_ulaw2lin(self):
+ # Cursory
+ d = audioop.lin2ulaw(data[0], 1)
+ self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
+
+ def test_mul(self):
+ data2 = []
+ for d in data:
+ str = bytearray(len(d))
+ for i,b in enumerate(d):
+ str[i] = 2*b
+ data2.append(str)
+ self.assertEqual(audioop.mul(data[0], 1, 2), data2[0])
+ self.assertEqual(audioop.mul(data[1],2, 2), data2[1])
+ self.assertEqual(audioop.mul(data[2], 4, 2), data2[2])
+
+ def test_ratecv(self):
+ state = None
+ d1, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
+ d2, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
+ self.assertEqual(d1 + d2, b'\000\000\001\001\002\001\000\000\001\001\002')
+
+ def test_reverse(self):
+ self.assertEqual(audioop.reverse(data[0], 1), b'\2\1\0')
+
+ def test_tomono(self):
+ data2 = bytearray()
+ for d in data[0]:
+ data2.append(d)
+ data2.append(d)
+ self.assertEqual(audioop.tomono(data2, 1, 0.5, 0.5), data[0])
+
+ def test_tostereo(self):
+ data2 = bytearray()
+ for d in data[0]:
+ data2.append(d)
+ data2.append(d)
+ self.assertEqual(audioop.tostereo(data[0], 1, 1, 1), data2)
+
+ def test_findfactor(self):
+ self.assertEqual(audioop.findfactor(data[1], data[1]), 1.0)
+
+ def test_findfit(self):
+ self.assertEqual(audioop.findfit(data[1], data[1]), (0, 1.0))
+
+ def test_findmax(self):
+ self.assertEqual(audioop.findmax(data[1], 1), 2)
+
+ def test_getsample(self):
+ for i in range(3):
+ self.assertEqual(audioop.getsample(data[0], 1, i), i)
+ self.assertEqual(audioop.getsample(data[1], 2, i), i)
+ self.assertEqual(audioop.getsample(data[2], 4, i), i)
+def test_main():
+ run_unittest(TestAudioop)
if __name__ == '__main__':
test_main()