Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_select.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | aa0d2d51fbde |
| children | 90342f395721 |
| rev | line source |
|---|---|
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 # Testing select module |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23846
diff
changeset
|
2 from test.test_support import verbose |
|
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 |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
5 |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
6 # test some known error conditions |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
7 try: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
8 rfd, wfd, xfd = select.select(1, 2, 3) |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
9 except TypeError: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
10 pass |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
11 else: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
12 print 'expected TypeError exception not raised' |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
13 |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
14 class Nope: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
15 pass |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
16 |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
17 class Almost: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
18 def fileno(self): |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
19 return 'fileno' |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
20 |
|
4691
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
21 try: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
22 rfd, wfd, xfd = select.select([Nope()], [], []) |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
23 except TypeError: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
24 pass |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
25 else: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
26 print 'expected TypeError exception not raised' |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
27 |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
28 try: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
29 rfd, wfd, xfd = select.select([Almost()], [], []) |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
30 except TypeError: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
31 pass |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
32 else: |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
33 print 'expected TypeError exception not raised' |
|
8015c5549309
A test of the select module that is actually reproduceable!
Barry Warsaw <barry@python.org>
parents:
1416
diff
changeset
|
34 |
|
23846
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
35 try: |
|
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
36 rfd, wfd, xfd = select.select([], [], [], 'not a number') |
|
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
37 except TypeError: |
|
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
38 pass |
|
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
39 else: |
|
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
40 print 'expected TypeError exception not raised' |
|
beb699e10b29
Test exceptional condition in select()
Neal Norwitz <nnorwitz@gmail.com>
parents:
15966
diff
changeset
|
41 |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 def test(): |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
44 import sys |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
45 if sys.platform[:3] in ('win', 'mac', 'os2'): |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
46 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
47 print "Can't test select easily on", sys.platform |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
48 return |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
49 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
50 p = os.popen(cmd, 'r') |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
51 for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
52 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
53 print 'timeout =', tout |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
54 rfd, wfd, xfd = select.select([p], [], [], tout) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
55 if (rfd, wfd, xfd) == ([], [], []): |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
56 continue |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
57 if (rfd, wfd, xfd) == ([p], [], []): |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
58 line = p.readline() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
59 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
60 print `line` |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
61 if not line: |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6626
diff
changeset
|
62 if verbose: |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
63 print 'EOF' |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
64 break |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
65 continue |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
66 print 'Unexpected return values from select():', rfd, wfd, xfd |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13707
diff
changeset
|
67 p.close() |
|
1407
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 |
|
b9fcfb99a3e5
* test_select.py: (some) tests for built-in select module
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 test() |
