1 from test
import test_support
2 test_support
.requires('audio')
4 from test
.test_support
import findfile
, run_unittest
11 linuxaudiodev
= test_support
.import_module('linuxaudiodev', deprecated
=True)
12 sunaudio
= test_support
.import_module('sunaudio', deprecated
=True)
14 SND_FORMAT_MULAW_8
= 1
16 class LinuxAudioDevTests(unittest
.TestCase
):
19 self
.dev
= linuxaudiodev
.open('w')
24 def test_methods(self
):
25 # at least check that these methods can be invoked
32 def test_play_sound_file(self
):
33 path
= findfile("audiotest.au")
35 size
, enc
, rate
, nchannels
, extra
= sunaudio
.gethdr(fp
)
39 if enc
!= SND_FORMAT_MULAW_8
:
40 self
.fail("Expect .au file with 8-bit mu-law samples")
42 # convert the data to 16-bit signed
43 data
= audioop
.ulaw2lin(data
, 2)
46 if sys
.byteorder
== 'little':
47 fmt
= linuxaudiodev
.AFMT_S16_LE
49 fmt
= linuxaudiodev
.AFMT_S16_BE
51 # set parameters based on .au file headers
52 self
.dev
.setparameters(rate
, 16, nchannels
, fmt
)
56 def test_errors(self
):
58 fmt
= linuxaudiodev
.AFMT_U8
62 self
.dev
.setparameters(-1, size
, nchannels
, fmt
)
63 except ValueError, err
:
64 self
.assertEquals(err
.args
[0], "expected rate >= 0, not -1")
66 self
.dev
.setparameters(rate
, -2, nchannels
, fmt
)
67 except ValueError, err
:
68 self
.assertEquals(err
.args
[0], "expected sample size >= 0, not -2")
70 self
.dev
.setparameters(rate
, size
, 3, fmt
)
71 except ValueError, err
:
72 self
.assertEquals(err
.args
[0], "nchannels must be 1 or 2, not 3")
74 self
.dev
.setparameters(rate
, size
, nchannels
, 177)
75 except ValueError, err
:
76 self
.assertEquals(err
.args
[0], "unknown audio encoding: 177")
78 self
.dev
.setparameters(rate
, size
, nchannels
, linuxaudiodev
.AFMT_U16_LE
)
79 except ValueError, err
:
80 self
.assertEquals(err
.args
[0], "for linear unsigned 16-bit little-endian "
81 "audio, expected sample size 16, not 8")
83 self
.dev
.setparameters(rate
, 16, nchannels
, fmt
)
84 except ValueError, err
:
85 self
.assertEquals(err
.args
[0], "for linear unsigned 8-bit audio, expected "
86 "sample size 8, not 16")
90 dsp
= linuxaudiodev
.open('w')
91 except linuxaudiodev
.error
, msg
:
92 if msg
.args
[0] in (errno
.EACCES
, errno
.ENOENT
, errno
.ENODEV
, errno
.EBUSY
):
93 raise unittest
.SkipTest(msg
)
96 run_unittest(LinuxAudioDevTests
)
98 if __name__
== '__main__':