Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_linuxaudiodev.py @ 57303:4aa4c19dfaed legacy-trunk
#1757126: fix typo with the cyrillic_asian alias
| author | Philip Jenvey <pjenvey@underboss.org> |
|---|---|
| date | Tue, 17 Nov 2009 02:42:26 +0000 |
| parents | 228cfb6e2900 |
| children | 7caf54ce529e |
| 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 | |
|
46851
1e427bc0f818
The linuxaudidev module has been deprecated for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
7 linuxaudiodev = test_support.import_module('linuxaudiodev', deprecated=True) |
|
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
|
8 import sys |
| 15062 | 9 import sunaudio |
|
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
|
10 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
|
11 import unittest |
| 15062 | 12 |
| 13 SND_FORMAT_MULAW_8 = 1 | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
15 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
|
16 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
17 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
|
18 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
|
19 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
20 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
|
21 self.dev.close() |
| 15062 | 22 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
23 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
|
24 # 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 self.dev.fileno() |
| 15062 | 30 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 fp.close() |
| 15062 | 37 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
38 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
|
39 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
|
40 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
41 # 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
|
42 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
|
43 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
44 # 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
|
45 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
|
46 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
|
47 else: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
48 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
|
49 |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
50 # 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
|
51 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
|
52 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
|
53 self.dev.flush() |
| 15062 | 54 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
61 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
|
62 except ValueError, err: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
63 self.assertEquals(err.args[0], "expected rate >= 0, not -1") |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
64 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
65 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
|
66 except ValueError, err: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
67 self.assertEquals(err.args[0], "expected sample size >= 0, not -2") |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
68 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
69 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
|
70 except ValueError, err: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
71 self.assertEquals(err.args[0], "nchannels must be 1 or 2, not 3") |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
72 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
73 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
|
74 except ValueError, err: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
75 self.assertEquals(err.args[0], "unknown audio encoding: 177") |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
76 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
77 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
|
78 except ValueError, err: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
79 self.assertEquals(err.args[0], "for linear unsigned 16-bit little-endian " |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
80 "audio, expected sample size 16, not 8") |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
81 try: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
82 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
|
83 except ValueError, err: |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
84 self.assertEquals(err.args[0], "for linear unsigned 8-bit audio, expected " |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
85 "sample size 8, not 16") |
| 15062 | 86 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
87 def test_main(): |
| 15062 | 88 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
|
89 dsp = linuxaudiodev.open('w') |
|
42791
a6e5b3868f3d
Catch the correct errors.
Georg Brandl <georg@python.org>
parents:
42787
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 raise |
|
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
94 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
|
95 run_unittest(LinuxAudioDevTests) |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
96 |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
36200
diff
changeset
|
97 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
|
98 test_main() |
