blob: 60de3600bc214c003b7c9c7648e259b591f03091 [file] [log] [blame]
Guido van Rossum5c971671996-07-22 15:23:25 +00001# Testing select module
Guido van Rossumde554ec1997-05-08 23:14:57 +00002from test_support import verbose
Guido van Rossum228b8e81997-04-02 06:13:34 +00003import 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):
Guido van Rossum548703a1998-03-26 22:14:20 +000019 return 'fileno'
Guido van Rossum228b8e81997-04-02 06:13:34 +000020
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
Guido van Rossum5c971671996-07-22 15:23:25 +000035
36def test():
Guido van Rossum548703a1998-03-26 22:14:20 +000037 import sys
38 if sys.platform[:3] in ('win', 'mac', 'os2'):
39 if verbose:
40 print "Can't test select easily on", sys.platform
41 return
42 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
43 p = os.popen(cmd, 'r')
44 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
45 if verbose:
46 print 'timeout =', tout
47 rfd, wfd, xfd = select.select([p], [], [], tout)
48## print rfd, wfd, xfd
49 if (rfd, wfd, xfd) == ([], [], []):
50 continue
51 if (rfd, wfd, xfd) == ([p], [], []):
52 line = p.readline()
53 if verbose:
54 print `line`
55 if not line:
56 if verbose:
57 print 'EOF'
58 break
59 continue
60 print 'Heh?'
61 p.close()
Guido van Rossum5c971671996-07-22 15:23:25 +000062
63test()
Guido van Rossum228b8e81997-04-02 06:13:34 +000064