Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_linuxaudiodev.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 4e31e4086849 |
| children | b3482164a100 |
| 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 |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23235
diff
changeset
|
4 from test.test_support import verbose, findfile, TestFailed, TestSkipped |
| 15062 | 5 |
| 6 import errno | |
| 7 import fcntl | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 import linuxaudiodev |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 import os |
|
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 sys |
| 15062 | 11 import select |
| 12 import sunaudio | |
| 13 import time | |
|
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
|
14 import audioop |
| 15062 | 15 |
| 16 SND_FORMAT_MULAW_8 = 1 | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 def play_sound_file(path): |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 fp = open(path, 'r') |
| 15062 | 20 size, enc, rate, nchannels, extra = sunaudio.gethdr(fp) |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 data = fp.read() |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 fp.close() |
| 15062 | 23 |
| 24 if enc != SND_FORMAT_MULAW_8: | |
| 25 print "Expect .au file with 8-bit mu-law samples" | |
| 26 return | |
| 27 | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 try: |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 a = linuxaudiodev.open('w') |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 except linuxaudiodev.error, msg: |
|
23235
770c2d2f5472
don't fail if the audio device is busy, just skip.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
15093
diff
changeset
|
31 if msg[0] in (errno.EACCES, errno.ENODEV, errno.EBUSY): |
|
13860
d74a4a43f45f
Oooopsss.....tab and space mismatch corrected.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
13857
diff
changeset
|
32 raise TestSkipped, msg |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 raise TestFailed, msg |
| 15062 | 34 |
|
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
|
35 # convert the data to 16-bit signed |
|
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
36 data = audioop.ulaw2lin(data, 2) |
|
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
37 |
|
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
38 # set the data format |
|
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
39 if sys.byteorder == 'little': |
|
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 fmt = linuxaudiodev.AFMT_S16_LE |
|
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 else: |
|
1b34c475da87
It seems our sound cards can't play mulaw data. Use native-format
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
42 fmt = linuxaudiodev.AFMT_S16_BE |
|
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 |
| 15062 | 44 # at least check that these methods can be invoked |
| 45 a.bufsize() | |
| 46 a.obufcount() | |
| 47 a.obuffree() | |
| 48 a.getptr() | |
| 49 a.fileno() | |
| 50 | |
| 51 # set parameters based on .au file headers | |
|
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
|
52 a.setparameters(rate, 16, nchannels, fmt) |
| 15062 | 53 a.write(data) |
| 54 a.flush() | |
| 55 a.close() | |
| 56 | |
| 57 def test_errors(): | |
| 58 a = linuxaudiodev.open("w") | |
| 59 size = 8 | |
| 60 fmt = linuxaudiodev.AFMT_U8 | |
| 61 rate = 8000 | |
| 62 nchannels = 1 | |
| 63 try: | |
| 64 a.setparameters(-1, size, nchannels, fmt) | |
| 65 except ValueError, msg: | |
| 66 print msg | |
| 67 try: | |
| 68 a.setparameters(rate, -2, nchannels, fmt) | |
| 69 except ValueError, msg: | |
| 70 print msg | |
| 71 try: | |
| 72 a.setparameters(rate, size, 3, fmt) | |
| 73 except ValueError, msg: | |
| 74 print msg | |
| 75 try: | |
| 76 a.setparameters(rate, size, nchannels, 177) | |
| 77 except ValueError, msg: | |
| 78 print msg | |
| 79 try: | |
| 80 a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE) | |
| 81 except ValueError, msg: | |
| 82 print msg | |
| 83 try: | |
| 84 a.setparameters(rate, 16, nchannels, fmt) | |
| 85 except ValueError, msg: | |
| 86 print msg | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
87 |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
88 def test(): |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
89 play_sound_file(findfile('audiotest.au')) |
| 15062 | 90 test_errors() |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
91 |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
92 test() |
