Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_linuxaudiodev.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | f51d1a2d4a4a |
| children | aa0d2d51fbde |
| rev | line source |
|---|---|
|
13857
a296ff55221f
Raise TestSkipped, not ImportError.
Moshe Zadka <moshez@math.huji.ac.il>
parents:
13855
diff
changeset
|
1 from test_support import verbose, findfile, TestFailed, TestSkipped |
| 15062 | 2 |
| 3 import errno | |
| 4 import fcntl | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 import linuxaudiodev |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 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
|
7 import sys |
| 15062 | 8 import select |
| 9 import sunaudio | |
| 10 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
|
11 import audioop |
| 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 |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 def play_sound_file(path): |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 fp = open(path, 'r') |
| 15062 | 17 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
|
18 data = fp.read() |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 fp.close() |
| 15062 | 20 |
| 21 if enc != SND_FORMAT_MULAW_8: | |
| 22 print "Expect .au file with 8-bit mu-law samples" | |
| 23 return | |
| 24 | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 try: |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 a = linuxaudiodev.open('w') |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 except linuxaudiodev.error, msg: |
| 23236 | 28 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
|
29 raise TestSkipped, msg |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 raise TestFailed, msg |
| 15062 | 31 |
|
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
|
32 # 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
|
33 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
|
34 |
|
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 # 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 |
| 15062 | 41 # at least check that these methods can be invoked |
| 42 a.bufsize() | |
| 43 a.obufcount() | |
| 44 a.obuffree() | |
| 45 a.getptr() | |
| 46 a.fileno() | |
| 47 | |
| 48 # 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
|
49 a.setparameters(rate, 16, nchannels, fmt) |
| 15062 | 50 a.write(data) |
| 51 a.flush() | |
| 52 a.close() | |
| 53 | |
| 54 def test_errors(): | |
| 55 a = linuxaudiodev.open("w") | |
| 56 size = 8 | |
| 57 fmt = linuxaudiodev.AFMT_U8 | |
| 58 rate = 8000 | |
| 59 nchannels = 1 | |
| 60 try: | |
| 61 a.setparameters(-1, size, nchannels, fmt) | |
| 62 except ValueError, msg: | |
| 63 print msg | |
| 64 try: | |
| 65 a.setparameters(rate, -2, nchannels, fmt) | |
| 66 except ValueError, msg: | |
| 67 print msg | |
| 68 try: | |
| 69 a.setparameters(rate, size, 3, fmt) | |
| 70 except ValueError, msg: | |
| 71 print msg | |
| 72 try: | |
| 73 a.setparameters(rate, size, nchannels, 177) | |
| 74 except ValueError, msg: | |
| 75 print msg | |
| 76 try: | |
| 77 a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE) | |
| 78 except ValueError, msg: | |
| 79 print msg | |
| 80 try: | |
| 81 a.setparameters(rate, 16, nchannels, fmt) | |
| 82 except ValueError, msg: | |
| 83 print msg | |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
84 |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
85 def test(): |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
86 play_sound_file(findfile('audiotest.au')) |
| 15062 | 87 test_errors() |
|
12908
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
88 |
|
1e784b879039
Added test for linnuxaudiodev module; directly adapted from sunaudiodev
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
89 test() |
