1 from test
import test_support
2 test_support
.requires('audio')
4 from test
.test_support
import findfile
, run_unittest
7 linuxaudiodev
= test_support
.import_module('linuxaudiodev', deprecated
=True)
13 SND_FORMAT_MULAW_8
= 1
15 class LinuxAudioDevTests(unittest
.TestCase
):
18 self
.dev
= linuxaudiodev
.open('w')
23 def test_methods(self
):
24 # at least check that these methods can be invoked
31 def test_play_sound_file(self
):
32 path
= findfile("audiotest.au")
34 size
, enc
, rate
, nchannels
, extra
= sunaudio
.gethdr(fp
)
38 if enc
!= SND_FORMAT_MULAW_8
:
39 self
.fail("Expect .au file with 8-bit mu-law samples")
41 # convert the data to 16-bit signed
42 data
= audioop
.ulaw2lin(data
, 2)
45 if sys
.byteorder
== 'little':
46 fmt
= linuxaudiodev
.AFMT_S16_LE
48 fmt
= linuxaudiodev
.AFMT_S16_BE
50 # set parameters based on .au file headers
51 self
.dev
.setparameters(rate
, 16, nchannels
, fmt
)
55 def test_errors(self
):
57 fmt
= linuxaudiodev
.AFMT_U8
61 self
.dev
.setparameters(-1, size
, nchannels
, fmt
)
62 except ValueError, err
:
63 self
.assertEquals(err
.args
[0], "expected rate >= 0, not -1")
65 self
.dev
.setparameters(rate
, -2, nchannels
, fmt
)
66 except ValueError, err
:
67 self
.assertEquals(err
.args
[0], "expected sample size >= 0, not -2")
69 self
.dev
.setparameters(rate
, size
, 3, fmt
)
70 except ValueError, err
:
71 self
.assertEquals(err
.args
[0], "nchannels must be 1 or 2, not 3")
73 self
.dev
.setparameters(rate
, size
, nchannels
, 177)
74 except ValueError, err
:
75 self
.assertEquals(err
.args
[0], "unknown audio encoding: 177")
77 self
.dev
.setparameters(rate
, size
, nchannels
, linuxaudiodev
.AFMT_U16_LE
)
78 except ValueError, err
:
79 self
.assertEquals(err
.args
[0], "for linear unsigned 16-bit little-endian "
80 "audio, expected sample size 16, not 8")
82 self
.dev
.setparameters(rate
, 16, nchannels
, fmt
)
83 except ValueError, err
:
84 self
.assertEquals(err
.args
[0], "for linear unsigned 8-bit audio, expected "
85 "sample size 8, not 16")
89 dsp
= linuxaudiodev
.open('w')
90 except linuxaudiodev
.error
, msg
:
91 if msg
.args
[0] in (errno
.EACCES
, errno
.ENOENT
, errno
.ENODEV
, errno
.EBUSY
):
92 raise unittest
.SkipTest(msg
)
95 run_unittest(LinuxAudioDevTests
)
97 if __name__
== '__main__':