blob: c96f711819fb96e01a6de3b19d44ab3a17643c6d [file] [log] [blame]
Benjamin Petersonbec087f2009-03-26 21:10:30 +00001from test.test_support import findfile, TestFailed, import_module
2import unittest
Brett Cannon22248172008-05-16 00:10:24 +00003sunaudiodev = import_module('sunaudiodev', deprecated=True)
Barry Warsaw5bc697d1997-01-07 21:05:29 +00004import os
5
Fred Drakeb8918912001-04-14 03:10:12 +00006try:
7 audiodev = os.environ["AUDIODEV"]
8except KeyError:
9 audiodev = "/dev/audio"
10
11if not os.path.exists(audiodev):
Benjamin Petersonbec087f2009-03-26 21:10:30 +000012 raise unittest.SkipTest("no audio device found!")
Fred Drakeb8918912001-04-14 03:10:12 +000013
Barry Warsaw5bc697d1997-01-07 21:05:29 +000014def play_sound_file(path):
15 fp = open(path, 'r')
16 data = fp.read()
17 fp.close()
Barry Warsaw3de721d1997-01-13 20:53:46 +000018 try:
Guido van Rossum41360a41998-03-26 19:42:58 +000019 a = sunaudiodev.open('w')
Barry Warsaw3de721d1997-01-13 20:53:46 +000020 except sunaudiodev.error, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +000021 raise TestFailed, msg
Barry Warsaw3de721d1997-01-13 20:53:46 +000022 else:
Guido van Rossum41360a41998-03-26 19:42:58 +000023 a.write(data)
24 a.close()
Barry Warsaw5bc697d1997-01-07 21:05:29 +000025
Brett Cannon7dbd9182008-03-03 04:19:29 +000026
27def test_main():
Barry Warsawb241c421997-01-13 20:34:44 +000028 play_sound_file(findfile('audiotest.au'))
Barry Warsaw5bc697d1997-01-07 21:05:29 +000029
Brett Cannon7dbd9182008-03-03 04:19:29 +000030
31
32if __name__ == '__main__':
33 test_main()