Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_ossaudiodev.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| rev | line source |
|---|---|
|
27896
4e31e4086849
- The audio driver tests (test_ossaudiodev.py and
Guido van Rossum <guido@python.org>
parents:
27154
diff
changeset
|
1 from test import test_support |
|
4e31e4086849
- The audio driver tests (test_ossaudiodev.py and
Guido van Rossum <guido@python.org>
parents:
27154
diff
changeset
|
2 test_support.requires('audio') |
|
4e31e4086849
- The audio driver tests (test_ossaudiodev.py and
Guido van Rossum <guido@python.org>
parents:
27154
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 |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
5 |
|
52491
f4c5e3a64be2
Change more tests to use import_module for the modules that
R. David Murray <rdmurray@bitdance.com>
parents:
52355
diff
changeset
|
6 ossaudiodev = test_support.import_module('ossaudiodev') |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
7 |
|
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
8 import errno |
|
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
9 import sys |
|
48020
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
10 import sunau |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
11 import time |
|
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
12 import audioop |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
13 import unittest |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
14 |
|
29359
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
15 # Arggh, AFMT_S16_NE not defined on all platforms -- seems to be a |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
16 # fairly recent addition to OSS. |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
17 try: |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
18 from ossaudiodev import AFMT_S16_NE |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
19 except ImportError: |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
20 if sys.byteorder == "little": |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
21 AFMT_S16_NE = ossaudiodev.AFMT_S16_LE |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
22 else: |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
23 AFMT_S16_NE = ossaudiodev.AFMT_S16_BE |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
24 |
|
ed949b82f95d
Factor endian-ness check out of play_sound_file(), and fix
Greg Ward <gward@python.net>
parents:
29297
diff
changeset
|
25 |
|
48020
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
26 def read_sound_file(path): |
|
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
27 with open(path, 'rb') as fp: |
|
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
28 au = sunau.open(fp) |
|
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
29 rate = au.getframerate() |
|
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
30 nchannels = au.getnchannels() |
|
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
31 encoding = au._encoding |
|
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
32 fp.seek(0) |
|
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
33 data = fp.read() |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
34 |
|
48020
f9040d107d66
Deprecate the sunaudio module for removal in Python 3.0. The sunau module can provide similar functionality.
Brett Cannon <bcannon@gmail.com>
parents:
45468
diff
changeset
|
35 if encoding != sunau.AUDIO_FILE_ENCODING_MULAW_8: |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
36 raise RuntimeError("Expect .au file with 8-bit mu-law samples") |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
37 |
|
26586
e64425bb94d8
Aesthetic tweakery: factor read_sound_file() out of play_sound_file().
Greg Ward <gward@python.net>
parents:
26585
diff
changeset
|
38 # Convert the data to 16-bit signed. |
|
e64425bb94d8
Aesthetic tweakery: factor read_sound_file() out of play_sound_file().
Greg Ward <gward@python.net>
parents:
26585
diff
changeset
|
39 data = audioop.ulaw2lin(data, 2) |
|
e64425bb94d8
Aesthetic tweakery: factor read_sound_file() out of play_sound_file().
Greg Ward <gward@python.net>
parents:
26585
diff
changeset
|
40 return (data, rate, 16, nchannels) |
|
e64425bb94d8
Aesthetic tweakery: factor read_sound_file() out of play_sound_file().
Greg Ward <gward@python.net>
parents:
26585
diff
changeset
|
41 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
42 class OSSAudioDevTests(unittest.TestCase): |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
43 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
44 def play_sound_file(self, data, rate, ssize, nchannels): |
|
34700
84859b4a62c6
SF #818006: merge from release24-maint branch: add useful read-only
Greg Ward <gward@python.net>
parents:
29738
diff
changeset
|
45 try: |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
46 dsp = ossaudiodev.open('w') |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
47 except IOError, msg: |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61785
diff
changeset
|
48 if msg.args[0] in (errno.EACCES, errno.ENOENT, |
|
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61785
diff
changeset
|
49 errno.ENODEV, errno.EBUSY): |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
50 raise unittest.SkipTest(msg) |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
51 raise |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
52 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
53 # at least check that these methods can be invoked |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
54 dsp.bufsize() |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
55 dsp.obufcount() |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
56 dsp.obuffree() |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
57 dsp.getptr() |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
58 dsp.fileno() |
|
34700
84859b4a62c6
SF #818006: merge from release24-maint branch: add useful read-only
Greg Ward <gward@python.net>
parents:
29738
diff
changeset
|
59 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
60 # Make sure the read-only attributes work. |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52491
diff
changeset
|
61 self.assertFalse(dsp.closed) |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
62 self.assertEqual(dsp.name, "/dev/dsp") |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
63 self.assertEqual(dsp.mode, "w", "bad dsp.mode: %r" % dsp.mode) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
64 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
65 # And make sure they're really read-only. |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
66 for attr in ('closed', 'name', 'mode'): |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
67 try: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
68 setattr(dsp, attr, 42) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
69 except TypeError: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
70 pass |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
71 else: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
72 self.fail("dsp.%s not read-only" % attr) |
|
39137
832fce50da93
Be a lot smarter about whether this test passes: instead of assuming
Greg Ward <gward@python.net>
parents:
36200
diff
changeset
|
73 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
74 # Compute expected running time of sound sample (in seconds). |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61785
diff
changeset
|
75 expected_time = float(len(data)) / (ssize//8) / nchannels / rate |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
76 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
77 # set parameters based on .au file headers |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
78 dsp.setparameters(AFMT_S16_NE, nchannels, rate) |
|
61785
38719f11619b
Merged revisions 80793 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents:
48254
diff
changeset
|
79 self.assertTrue(abs(expected_time - 3.51) < 1e-2, expected_time) |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
80 t1 = time.time() |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
81 dsp.write(data) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
82 dsp.close() |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
83 t2 = time.time() |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
84 elapsed_time = t2 - t1 |
|
39137
832fce50da93
Be a lot smarter about whether this test passes: instead of assuming
Greg Ward <gward@python.net>
parents:
36200
diff
changeset
|
85 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
86 percent_diff = (abs(elapsed_time - expected_time) / expected_time) * 100 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52491
diff
changeset
|
87 self.assertTrue(percent_diff <= 10.0, |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
88 "elapsed time > 10% off of expected time") |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
89 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
90 def set_parameters(self, dsp): |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
91 # Two configurations for testing: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
92 # config1 (8-bit, mono, 8 kHz) should work on even the most |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
93 # ancient and crufty sound card, but maybe not on special- |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
94 # purpose high-end hardware |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
95 # config2 (16-bit, stereo, 44.1kHz) should work on all but the |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
96 # most ancient and crufty hardware |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
97 config1 = (ossaudiodev.AFMT_U8, 1, 8000) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
98 config2 = (AFMT_S16_NE, 2, 44100) |
|
29297
c1e80f2f1c47
Renamed test_errors() to test_setparameters() and completely rewrote it
Greg Ward <gward@python.net>
parents:
29296
diff
changeset
|
99 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
100 for config in [config1, config2]: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
101 (fmt, channels, rate) = config |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
102 if (dsp.setfmt(fmt) == fmt and |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
103 dsp.channels(channels) == channels and |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
104 dsp.speed(rate) == rate): |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
105 break |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
106 else: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
107 raise RuntimeError("unable to set audio sampling parameters: " |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
108 "you must have really weird audio hardware") |
|
29297
c1e80f2f1c47
Renamed test_errors() to test_setparameters() and completely rewrote it
Greg Ward <gward@python.net>
parents:
29296
diff
changeset
|
109 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
110 # setparameters() should be able to set this configuration in |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
111 # either strict or non-strict mode. |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
112 result = dsp.setparameters(fmt, channels, rate, False) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
113 self.assertEqual(result, (fmt, channels, rate), |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
114 "setparameters%r: returned %r" % (config, result)) |
|
29297
c1e80f2f1c47
Renamed test_errors() to test_setparameters() and completely rewrote it
Greg Ward <gward@python.net>
parents:
29296
diff
changeset
|
115 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
116 result = dsp.setparameters(fmt, channels, rate, True) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
117 self.assertEqual(result, (fmt, channels, rate), |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
118 "setparameters%r: returned %r" % (config, result)) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
119 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
120 def set_bad_parameters(self, dsp): |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
121 # Now try some configurations that are presumably bogus: eg. 300 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
122 # channels currently exceeds even Hollywood's ambitions, and |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
123 # negative sampling rate is utter nonsense. setparameters() should |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
124 # accept these in non-strict mode, returning something other than |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
125 # was requested, but should barf in strict mode. |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
126 fmt = AFMT_S16_NE |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
127 rate = 44100 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
128 channels = 2 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
129 for config in [(fmt, 300, rate), # ridiculous nchannels |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
130 (fmt, -5, rate), # impossible nchannels |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
131 (fmt, channels, -50), # impossible rate |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
132 ]: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
133 (fmt, channels, rate) = config |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
134 result = dsp.setparameters(fmt, channels, rate, False) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52491
diff
changeset
|
135 self.assertNotEqual(result, config, |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
136 "unexpectedly got requested configuration") |
|
29297
c1e80f2f1c47
Renamed test_errors() to test_setparameters() and completely rewrote it
Greg Ward <gward@python.net>
parents:
29296
diff
changeset
|
137 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
138 try: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
139 result = dsp.setparameters(fmt, channels, rate, True) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
140 except ossaudiodev.OSSAudioError, err: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
141 pass |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
142 else: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
143 self.fail("expected OSSAudioError") |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
144 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
145 def test_playback(self): |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
146 sound_info = read_sound_file(findfile('audiotest.au')) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
147 self.play_sound_file(*sound_info) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
148 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
149 def test_set_parameters(self): |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
150 dsp = ossaudiodev.open("w") |
|
29297
c1e80f2f1c47
Renamed test_errors() to test_setparameters() and completely rewrote it
Greg Ward <gward@python.net>
parents:
29296
diff
changeset
|
151 try: |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
152 self.set_parameters(dsp) |
|
34700
84859b4a62c6
SF #818006: merge from release24-maint branch: add useful read-only
Greg Ward <gward@python.net>
parents:
29738
diff
changeset
|
153 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
154 # Disabled because it fails under Linux 2.6 with ALSA's OSS |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
155 # emulation layer. |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
156 #self.set_bad_parameters(dsp) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
157 finally: |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
158 dsp.close() |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
52491
diff
changeset
|
159 self.assertTrue(dsp.closed) |
|
34700
84859b4a62c6
SF #818006: merge from release24-maint branch: add useful read-only
Greg Ward <gward@python.net>
parents:
29738
diff
changeset
|
160 |
|
26585
3f4383a04b62
Initial revision is rev 1.8 of test_linuxaudiodev.py, with
Greg Ward <gward@python.net>
parents:
diff
changeset
|
161 |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
162 def test_main(): |
|
41542
073d68c29049
Fix an issue related to the unittest conversion.
Collin Winter <collinw@gmail.com>
parents:
41541
diff
changeset
|
163 try: |
|
073d68c29049
Fix an issue related to the unittest conversion.
Collin Winter <collinw@gmail.com>
parents:
41541
diff
changeset
|
164 dsp = ossaudiodev.open('w') |
|
42872
ff3c0be71dc2
Catch IOError for when the device file doesn't exist or the user doesn't have
Neal Norwitz <nnorwitz@gmail.com>
parents:
42791
diff
changeset
|
165 except (ossaudiodev.error, IOError), msg: |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61785
diff
changeset
|
166 if msg.args[0] in (errno.EACCES, errno.ENOENT, |
|
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61785
diff
changeset
|
167 errno.ENODEV, errno.EBUSY): |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
168 raise unittest.SkipTest(msg) |
|
41542
073d68c29049
Fix an issue related to the unittest conversion.
Collin Winter <collinw@gmail.com>
parents:
41541
diff
changeset
|
169 raise |
|
42787
48d91f1558a0
Convert test_linuxaudiodev to unittest. Fix a wrong finally clause in test_ossaudiodev.
Georg Brandl <georg@python.org>
parents:
42786
diff
changeset
|
170 dsp.close() |
|
41541
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
171 test_support.run_unittest(__name__) |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
172 |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
173 if __name__ == "__main__": |
|
0f29a1a0972c
Convert test_ossaudiodev to use unittest.
Collin Winter <collinw@gmail.com>
parents:
39176
diff
changeset
|
174 test_main() |
