Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_poll.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | d4e7470bd660 |
| children | 974ace29ee2d 520adfab957e |
| rev | line source |
|---|---|
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1 # Test case for the os.poll() function |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14247
diff
changeset
|
2 |
|
45471
7dd2c1746267
Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43014
diff
changeset
|
3 import os, select, random, unittest |
|
52389
d4e7470bd660
Merged revisions 70554,70588-70589,70598,70605,70611-70621,70623-70624,70626-70627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
4 from test.support import TESTFN, run_unittest |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
5 |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
6 try: |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
7 select.poll |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
8 except AttributeError: |
|
52389
d4e7470bd660
Merged revisions 70554,70588-70589,70598,70605,70611-70621,70623-70624,70626-70627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
9 raise unittest.SkipTest("select.poll not defined -- skipping test_poll") |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
10 |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
11 |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
12 def find_ready_matching(ready, flag): |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
13 match = [] |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
14 for fd, mode in ready: |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
15 if mode & flag: |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
16 match.append(fd) |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
17 return match |
|
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
18 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
19 class PollTests(unittest.TestCase): |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
20 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
21 def test_poll1(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
22 # Basic functional test of poll object |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
23 # Create a bunch of pipe and test that poll works with them. |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
24 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
25 p = select.poll() |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
26 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
27 NUM_PIPES = 12 |
|
42205
9b72f0636986
Fix test_poll.py. By Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
40644
diff
changeset
|
28 MSG = b" This is a test." |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
29 MSG_LEN = len(MSG) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
30 readers = [] |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
31 writers = [] |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
32 r2w = {} |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
33 w2r = {} |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
34 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
35 for i in range(NUM_PIPES): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
36 rd, wr = os.pipe() |
|
45996
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45471
diff
changeset
|
37 p.register(rd) |
|
376b5cb8a014
Merged revisions 61687-61688,61696,61700,61704-61705,61707-61709,61711-61712,61714-61716,61718-61722 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45471
diff
changeset
|
38 p.modify(rd, select.POLLIN) |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
39 p.register(wr, select.POLLOUT) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
40 readers.append(rd) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
41 writers.append(wr) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
42 r2w[rd] = wr |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
43 w2r[wr] = rd |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
44 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
45 bufs = [] |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
46 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
47 while writers: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
48 ready = p.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
49 ready_writers = find_ready_matching(ready, select.POLLOUT) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
50 if not ready_writers: |
|
43014
9834301a2fd3
Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents:
42205
diff
changeset
|
51 raise RuntimeError("no pipes ready for writing") |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
52 wr = random.choice(ready_writers) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
53 os.write(wr, MSG) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
54 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
55 ready = p.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
56 ready_readers = find_ready_matching(ready, select.POLLIN) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
57 if not ready_readers: |
|
43014
9834301a2fd3
Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents:
42205
diff
changeset
|
58 raise RuntimeError("no pipes ready for reading") |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
59 rd = random.choice(ready_readers) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
60 buf = os.read(rd, MSG_LEN) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
61 self.assertEqual(len(buf), MSG_LEN) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
62 bufs.append(buf) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
63 os.close(r2w[rd]) ; os.close( rd ) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
64 p.unregister( r2w[rd] ) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
65 p.unregister( rd ) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
66 writers.remove(r2w[rd]) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
67 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
68 self.assertEqual(bufs, [MSG] * NUM_PIPES) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
69 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
70 def poll_unit_tests(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
71 # returns NVAL for invalid file descriptor |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
72 FD = 42 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
73 try: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
74 os.close(FD) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
75 except OSError: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
76 pass |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
77 p = select.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
78 p.register(FD) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
79 r = p.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
80 self.assertEqual(r[0], (FD, select.POLLNVAL)) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
81 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
82 f = open(TESTFN, 'w') |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
83 fd = f.fileno() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
84 p = select.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
85 p.register(f) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
86 r = p.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
87 self.assertEqual(r[0][0], fd) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
88 f.close() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
89 r = p.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
90 self.assertEqual(r[0], (fd, select.POLLNVAL)) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
91 os.unlink(TESTFN) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
92 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
93 # type error for invalid arguments |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
94 p = select.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
95 self.assertRaises(TypeError, p.register, p) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
96 self.assertRaises(TypeError, p.unregister, p) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
97 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
98 # can't unregister non-existent object |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
99 p = select.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
100 self.assertRaises(KeyError, p.unregister, 3) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
101 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
102 # Test error cases |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
103 pollster = select.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
104 class Nope: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
105 pass |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
106 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
107 class Almost: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
108 def fileno(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
109 return 'fileno' |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
110 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
111 self.assertRaises(TypeError, pollster.register, Nope(), 0) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
112 self.assertRaises(TypeError, pollster.register, Almost(), 0) |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
113 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
114 # Another test case for poll(). This is copied from the test case for |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
115 # select(), modified to use poll() instead. |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
116 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
117 def test_poll2(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
118 cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
119 p = os.popen(cmd, 'r') |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
120 pollster = select.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
121 pollster.register( p, select.POLLIN ) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
122 for tout in (0, 1000, 2000, 4000, 8000, 16000) + (-1,)*10: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
123 fdlist = pollster.poll(tout) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
124 if (fdlist == []): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
125 continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
126 fd, flags = fdlist[0] |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
127 if flags & select.POLLHUP: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
128 line = p.readline() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
129 if line != "": |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
130 self.fail('error: pipe seems to be closed, but still returns data') |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
131 continue |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
132 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
133 elif flags & select.POLLIN: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
134 line = p.readline() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
135 if not line: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
136 break |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
137 continue |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
138 else: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
139 self.fail('Unexpected return value from select.poll: %s' % fdlist) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
140 p.close() |
|
14175
8d1a059ae99d
Test suite for poll() interface (SF patch #100852)
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
141 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
142 def test_poll3(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
143 # test int overflow |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
144 pollster = select.poll() |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
145 pollster.register(1) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
146 |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
147 self.assertRaises(OverflowError, pollster.poll, 1 << 64) |
|
35834
418a61ead11b
Bug #1346533, select.poll() doesn't raise an error if timeout > sys.maxint
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
148 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
149 x = 2 + 3 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
150 if x != 5: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
151 self.fail('Overflow must have occurred') |
|
35834
418a61ead11b
Bug #1346533, select.poll() doesn't raise an error if timeout > sys.maxint
Neal Norwitz <nnorwitz@gmail.com>
parents:
31515
diff
changeset
|
152 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
153 def test_main(): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
154 run_unittest(PollTests) |
|
36121
686306a67e9b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35834
diff
changeset
|
155 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
156 if __name__ == '__main__': |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
36121
diff
changeset
|
157 test_main() |
