move sections
[python/dscho.git] / Lib / test / test_select.py
blob79b249bf411033d5ff8431d98fbbd3520767a4e8
1 from test import test_support
2 import unittest
3 import select
4 import os
5 import sys
7 @unittest.skipIf(sys.platform[:3] in ('win', 'os2', 'riscos'),
8 "can't easily test on this system")
9 class SelectTestCase(unittest.TestCase):
11 class Nope:
12 pass
14 class Almost:
15 def fileno(self):
16 return 'fileno'
18 def test_error_conditions(self):
19 self.assertRaises(TypeError, select.select, 1, 2, 3)
20 self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
21 self.assertRaises(TypeError, select.select, [self.Almost()], [], [])
22 self.assertRaises(TypeError, select.select, [], [], [], "not a number")
24 def test_returned_list_identity(self):
25 # See issue #8329
26 r, w, x = select.select([], [], [], 1)
27 self.assertIsNot(r, w)
28 self.assertIsNot(r, x)
29 self.assertIsNot(w, x)
31 def test_select(self):
32 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
33 p = os.popen(cmd, 'r')
34 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
35 if test_support.verbose:
36 print 'timeout =', tout
37 rfd, wfd, xfd = select.select([p], [], [], tout)
38 if (rfd, wfd, xfd) == ([], [], []):
39 continue
40 if (rfd, wfd, xfd) == ([p], [], []):
41 line = p.readline()
42 if test_support.verbose:
43 print repr(line)
44 if not line:
45 if test_support.verbose:
46 print 'EOF'
47 break
48 continue
49 self.fail('Unexpected return values from select():', rfd, wfd, xfd)
50 p.close()
53 def test_main():
54 test_support.run_unittest(SelectTestCase)
55 test_support.reap_children()
57 if __name__ == "__main__":
58 test_main()