Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_linuxaudiodev.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
|
27896
4e31e4086849
- The audio driver tests (test_ossaudiodev.py and
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
1 from test import test_support |
|
4e31e4086849
- The audio driver tests (test_ossaudiodev.py and
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
2 test_support.requires('audio') |
|
4e31e4086849
- The audio driver tests (test_ossaudiodev.py and
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
3 |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
4 from test.test_support import findfile, run_unittest |
| 15062 | 5 |
| 6 import errno | |
|
15093
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
7 import sys |
|
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
8 import audioop |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
9 import unittest |
| 15062 | 10 |
|
63531
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
46851
diff
changeset
|
11 linuxaudiodev = test_support.import_module('linuxaudiodev', deprecated=True) |
|
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
46851
diff
changeset
|
12 sunaudio = test_support.import_module('sunaudio', deprecated=True) |
|
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
46851
diff
changeset
|
13 |
| 15062 | 14 SND_FORMAT_MULAW_8 = 1 |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
16 class LinuxAudioDevTests(unittest.TestCase): |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
17 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
18 def setUp(self): |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
19 self.dev = linuxaudiodev.open('w') |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
20 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
21 def tearDown(self): |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
22 self.dev.close() |
| 15062 | 23 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
24 def test_methods(self): |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
25 # at least check that these methods can be invoked |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
26 self.dev.bufsize() |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
27 self.dev.obufcount() |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
28 self.dev.obuffree() |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
29 self.dev.getptr() |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
30 self.dev.fileno() |
| 15062 | 31 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
32 def test_play_sound_file(self): |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
33 path = findfile("audiotest.au") |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
34 fp = open(path, 'r') |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
35 size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
36 data = fp.read() |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
37 fp.close() |
| 15062 | 38 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
39 if enc != SND_FORMAT_MULAW_8: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
40 self.fail("Expect .au file with 8-bit mu-law samples") |
|
15093
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
41 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
42 # convert the data to 16-bit signed |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
43 data = audioop.ulaw2lin(data, 2) |
|
15093
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
44 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
45 # set the data format |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
46 if sys.byteorder == 'little': |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
47 fmt = linuxaudiodev.AFMT_S16_LE |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
48 else: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
49 fmt = linuxaudiodev.AFMT_S16_BE |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
50 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
51 # set parameters based on .au file headers |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
52 self.dev.setparameters(rate, 16, nchannels, fmt) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
53 self.dev.write(data) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
54 self.dev.flush() |
| 15062 | 55 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
56 def test_errors(self): |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
57 size = 8 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
58 fmt = linuxaudiodev.AFMT_U8 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
59 rate = 8000 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
60 nchannels = 1 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
61 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
62 self.dev.setparameters(-1, size, nchannels, fmt) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
63 except ValueError, err: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
64 self.assertEqual(err.args[0], "expected rate >= 0, not -1") |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
65 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
66 self.dev.setparameters(rate, -2, nchannels, fmt) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
67 except ValueError, err: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
68 self.assertEqual(err.args[0], "expected sample size >= 0, not -2") |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
69 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
70 self.dev.setparameters(rate, size, 3, fmt) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
71 except ValueError, err: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
72 self.assertEqual(err.args[0], "nchannels must be 1 or 2, not 3") |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
73 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
74 self.dev.setparameters(rate, size, nchannels, 177) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
75 except ValueError, err: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
76 self.assertEqual(err.args[0], "unknown audio encoding: 177") |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
77 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
78 self.dev.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
79 except ValueError, err: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
80 self.assertEqual(err.args[0], "for linear unsigned 16-bit little-endian " |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
81 "audio, expected sample size 16, not 8") |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
82 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
83 self.dev.setparameters(rate, 16, nchannels, fmt) |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
84 except ValueError, err: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
85 self.assertEqual(err.args[0], "for linear unsigned 8-bit audio, expected " |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58580
diff
changeset
|
86 "sample size 8, not 16") |
| 15062 | 87 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
88 def test_main(): |
| 15062 | 89 try: |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
90 dsp = linuxaudiodev.open('w') |
|
42791
a6e5b3868f3d
Catch the correct errors.
Georg Brandl <georg@python.org>
parents:
42787
diff
changeset
|
91 except linuxaudiodev.error, msg: |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
92 if msg.args[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
93 raise unittest.SkipTest(msg) |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
94 raise |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
95 dsp.close() |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
96 run_unittest(LinuxAudioDevTests) |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
97 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
98 if __name__ == '__main__': |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
99 test_main() |
