Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / test / test_select.py
CommitLineData
920dae64
AT
1# Testing select module
2from test.test_support import verbose
3import select
4import os
5
6# test some known error conditions
7try:
8 rfd, wfd, xfd = select.select(1, 2, 3)
9except TypeError:
10 pass
11else:
12 print 'expected TypeError exception not raised'
13
14class Nope:
15 pass
16
17class Almost:
18 def fileno(self):
19 return 'fileno'
20
21try:
22 rfd, wfd, xfd = select.select([Nope()], [], [])
23except TypeError:
24 pass
25else:
26 print 'expected TypeError exception not raised'
27
28try:
29 rfd, wfd, xfd = select.select([Almost()], [], [])
30except TypeError:
31 pass
32else:
33 print 'expected TypeError exception not raised'
34
35try:
36 rfd, wfd, xfd = select.select([], [], [], 'not a number')
37except TypeError:
38 pass
39else:
40 print 'expected TypeError exception not raised'
41
42
43def test():
44 import sys
45 if sys.platform[:3] in ('win', 'mac', 'os2', 'riscos'):
46 if verbose:
47 print "Can't test select easily on", sys.platform
48 return
49 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
50 p = os.popen(cmd, 'r')
51 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
52 if verbose:
53 print 'timeout =', tout
54 rfd, wfd, xfd = select.select([p], [], [], tout)
55 if (rfd, wfd, xfd) == ([], [], []):
56 continue
57 if (rfd, wfd, xfd) == ([p], [], []):
58 line = p.readline()
59 if verbose:
60 print repr(line)
61 if not line:
62 if verbose:
63 print 'EOF'
64 break
65 continue
66 print 'Unexpected return values from select():', rfd, wfd, xfd
67 p.close()
68
69test()