blob: d5bcfd554723271e5daab4e81f53066686182bc0 [file] [log] [blame]
Guido van Rossumb31c7f71993-11-11 10:31:23 +00001# Testing select module
Guido van Rossum684480f1997-04-16 00:29:59 +00002from test_support import verbose
Barry Warsaw792c94a1996-12-11 23:58:46 +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 Rossum41360a41998-03-26 19:42:58 +000019 return 'fileno'
Fred Drake004d5e62000-10-23 17:22:08 +000020
Barry Warsaw792c94a1996-12-11 23:58:46 +000021try:
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 Rossumb31c7f71993-11-11 10:31:23 +000035
Guido van Rossumb31c7f71993-11-11 10:31:23 +000036def test():
Fred Drake004d5e62000-10-23 17:22:08 +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 if (rfd, wfd, xfd) == ([], [], []):
49 continue
50 if (rfd, wfd, xfd) == ([p], [], []):
51 line = p.readline()
52 if verbose:
53 print `line`
54 if not line:
Guido van Rossum41360a41998-03-26 19:42:58 +000055 if verbose:
Fred Drake004d5e62000-10-23 17:22:08 +000056 print 'EOF'
57 break
58 continue
59 print 'Unexpected return values from select():', rfd, wfd, xfd
60 p.close()
Guido van Rossumb31c7f71993-11-11 10:31:23 +000061
62test()