0001 # Testing select module 0002 from test.test_support import verbose 0003 import select 0004 import os 0005 0006 # test some known error conditions 0007 try: 0008 rfd, wfd, xfd = select.select(1, 2, 3) 0009 except TypeError: 0010 pass 0011 else: 0012 print 'expected TypeError exception not raised' 0013 0014 class Nope: 0015 pass 0016 0017 class Almost: 0018 def fileno(self): 0019 return 'fileno' 0020 0021 try: 0022 rfd, wfd, xfd = select.select([Nope()], [], []) 0023 except TypeError: 0024 pass 0025 else: 0026 print 'expected TypeError exception not raised' 0027 0028 try: 0029 rfd, wfd, xfd = select.select([Almost()], [], []) 0030 except TypeError: 0031 pass 0032 else: 0033 print 'expected TypeError exception not raised' 0034 0035 try: 0036 rfd, wfd, xfd = select.select([], [], [], 'not a number') 0037 except TypeError: 0038 pass 0039 else: 0040 print 'expected TypeError exception not raised' 0041 0042 0043 def test(): 0044 import sys 0045 if sys.platform[:3] in ('win', 'mac', 'os2', 'riscos'): 0046 if verbose: 0047 print "Can't test select easily on", sys.platform 0048 return 0049 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' 0050 p = os.popen(cmd, 'r') 0051 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: 0052 if verbose: 0053 print 'timeout =', tout 0054 rfd, wfd, xfd = select.select([p], [], [], tout) 0055 if (rfd, wfd, xfd) == ([], [], []): 0056 continue 0057 if (rfd, wfd, xfd) == ([p], [], []): 0058 line = p.readline() 0059 if verbose: 0060 print repr(line) 0061 if not line: 0062 if verbose: 0063 print 'EOF' 0064 break 0065 continue 0066 print 'Unexpected return values from select():', rfd, wfd, xfd 0067 p.close() 0068 0069 test() 0070
Generated by PyXR 0.9.4