| 
									
										
										
										
											1993-11-11 10:31:23 +00:00
										 |  |  | # Testing select module | 
					
						
							| 
									
										
										
										
											2006-06-29 04:10:08 +00:00
										 |  |  | from test.test_support import verbose, reap_children | 
					
						
							| 
									
										
										
										
											1996-12-11 23:58:46 +00:00
										 |  |  | import select | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # test some known error conditions | 
					
						
							|  |  |  | try: | 
					
						
							|  |  |  |     rfd, wfd, xfd = select.select(1, 2, 3) | 
					
						
							|  |  |  | except TypeError: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     print 'expected TypeError exception not raised' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Nope: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Almost: | 
					
						
							|  |  |  |     def fileno(self): | 
					
						
							| 
									
										
										
										
											1998-03-26 19:42:58 +00:00
										 |  |  |         return 'fileno' | 
					
						
							| 
									
										
										
										
											2000-10-23 17:22:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-12-11 23:58:46 +00:00
										 |  |  | try: | 
					
						
							|  |  |  |     rfd, wfd, xfd = select.select([Nope()], [], []) | 
					
						
							|  |  |  | except TypeError: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     print 'expected TypeError exception not raised' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							|  |  |  |     rfd, wfd, xfd = select.select([Almost()], [], []) | 
					
						
							|  |  |  | except TypeError: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     print 'expected TypeError exception not raised' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-13 22:23:47 +00:00
										 |  |  | try: | 
					
						
							|  |  |  |     rfd, wfd, xfd = select.select([], [], [], 'not a number') | 
					
						
							|  |  |  | except TypeError: | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     print 'expected TypeError exception not raised' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1993-11-11 10:31:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test(): | 
					
						
							| 
									
										
										
										
											2000-10-23 17:22:08 +00:00
										 |  |  |     import sys | 
					
						
							| 
									
										
										
										
											2003-05-10 07:36:56 +00:00
										 |  |  |     if sys.platform[:3] in ('win', 'mac', 'os2', 'riscos'): | 
					
						
							| 
									
										
										
										
											2000-10-23 17:22:08 +00:00
										 |  |  |         if verbose: | 
					
						
							|  |  |  |             print "Can't test select easily on", sys.platform | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' | 
					
						
							|  |  |  |     p = os.popen(cmd, 'r') | 
					
						
							|  |  |  |     for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: | 
					
						
							|  |  |  |         if verbose: | 
					
						
							|  |  |  |             print 'timeout =', tout | 
					
						
							|  |  |  |         rfd, wfd, xfd = select.select([p], [], [], tout) | 
					
						
							|  |  |  |         if (rfd, wfd, xfd) == ([], [], []): | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if (rfd, wfd, xfd) == ([p], [], []): | 
					
						
							|  |  |  |             line = p.readline() | 
					
						
							|  |  |  |             if verbose: | 
					
						
							| 
									
										
										
										
											2004-02-12 17:35:32 +00:00
										 |  |  |                 print repr(line) | 
					
						
							| 
									
										
										
										
											2000-10-23 17:22:08 +00:00
										 |  |  |             if not line: | 
					
						
							| 
									
										
										
										
											1998-03-26 19:42:58 +00:00
										 |  |  |                 if verbose: | 
					
						
							| 
									
										
										
										
											2000-10-23 17:22:08 +00:00
										 |  |  |                     print 'EOF' | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         print 'Unexpected return values from select():', rfd, wfd, xfd | 
					
						
							|  |  |  |     p.close() | 
					
						
							| 
									
										
										
										
											2006-06-29 04:10:08 +00:00
										 |  |  |     reap_children() | 
					
						
							| 
									
										
										
										
											1993-11-11 10:31:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | test() |