Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_select.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 49dc9af90b3d |
| children | eec2db09a6c1 9ba8c6e52fa0 |
| rev | line source |
|---|---|
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
1 from test import test_support |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
2 import unittest |
|
4691
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
3 import select |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
4 import os |
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
5 import sys |
|
4691
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
6 |
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
7 class SelectTestCase(unittest.TestCase): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
8 |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
9 class Nope: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
10 pass |
|
4691
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
11 |
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
12 class Almost: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
13 def fileno(self): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
14 return 'fileno' |
|
4691
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
15 |
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
16 def test_error_conditions(self): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
17 self.assertRaises(TypeError, select.select, 1, 2, 3) |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
18 self.assertRaises(TypeError, select.select, [self.Nope()], [], []) |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
19 self.assertRaises(TypeError, select.select, [self.Almost()], [], []) |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
20 self.assertRaises(TypeError, select.select, [], [], [], "not a number") |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
21 |
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
22 def test_select(self): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
23 if sys.platform[:3] in ('win', 'mac', 'os2', 'riscos'): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
24 if test_support.verbose: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
25 print "Can't test select easily on", sys.platform |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
26 return |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
27 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
28 p = os.popen(cmd, 'r') |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
29 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
30 if test_support.verbose: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
31 print 'timeout =', tout |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
32 rfd, wfd, xfd = select.select([p], [], [], tout) |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
33 if (rfd, wfd, xfd) == ([], [], []): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
34 continue |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
35 if (rfd, wfd, xfd) == ([p], [], []): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
36 line = p.readline() |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
37 if test_support.verbose: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
38 print repr(line) |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
39 if not line: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
40 if test_support.verbose: |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
41 print 'EOF' |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
42 break |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
43 continue |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
44 self.fail('Unexpected return values from select():', rfd, wfd, xfd) |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
45 p.close() |
|
23846
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
46 |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
48 def test_main(): |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
49 test_support.run_unittest(SelectTestCase) |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
50 test_support.reap_children() |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 |
|
45751
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
52 if __name__ == "__main__": |
|
49dc9af90b3d
Convert test_contains, test_crypt, and test_select to unittest.
Brett Cannon <bcannon@gmail.com>
parents:
38961
diff
changeset
|
53 test_main() |
