Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5bc697d

Browse files
committed
Test of the sunaudiodev module -- it simply plays a sound if it can
find one and doesn't output any data that can be verified. If it can't find a sound file by looking in the standard Solaris locations (which we can extend later), it raises an ImportError.
1 parent dce1005 commit 5bc697d

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lib/test/output/test_sunaudiodev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test_sunaudiodev

Lib/test/test_sunaudiodev.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from test_support import verbose, TestFailed
2+
import sunaudiodev
3+
import os
4+
5+
OS_AUDIO_DIRS = [
6+
'/usr/demo/SOUND/sounds/', # Solaris 2.x
7+
]
8+
9+
10+
def play_sound_file(path):
11+
fp = open(path, 'r')
12+
data = fp.read()
13+
fp.close()
14+
a = sunaudiodev.open('w')
15+
a.write(data)
16+
a.close()
17+
18+
def test():
19+
for d in OS_AUDIO_DIRS:
20+
try:
21+
files = os.listdir(d)
22+
break
23+
except os.error:
24+
pass
25+
else:
26+
# test couldn't be conducted on this platform
27+
raise ImportError
28+
for f in files:
29+
path = os.path.join(d, f)
30+
try:
31+
play_sound_file(path)
32+
break
33+
except:
34+
pass
35+
else:
36+
raise TestFailed, "couldn't play any sounds"
37+
38+
test()

0 commit comments

Comments
 (0)