(self)
| 31 | class PollTests(unittest.TestCase): |
| 32 | |
| 33 | def test_poll1(self): |
| 34 | # Basic functional test of poll object |
| 35 | # Create a bunch of pipe and test that poll works with them. |
| 36 | |
| 37 | p = select.poll() |
| 38 | |
| 39 | NUM_PIPES = 12 |
| 40 | MSG = b" This is a test." |
| 41 | MSG_LEN = len(MSG) |
| 42 | readers = [] |
| 43 | writers = [] |
| 44 | r2w = {} |
| 45 | w2r = {} |
| 46 | |
| 47 | for i in range(NUM_PIPES): |
| 48 | rd, wr = os.pipe() |
| 49 | p.register(rd) |
| 50 | p.modify(rd, select.POLLIN) |
| 51 | p.register(wr, select.POLLOUT) |
| 52 | readers.append(rd) |
| 53 | writers.append(wr) |
| 54 | r2w[rd] = wr |
| 55 | w2r[wr] = rd |
| 56 | |
| 57 | bufs = [] |
| 58 | |
| 59 | while writers: |
| 60 | ready = p.poll() |
| 61 | ready_writers = find_ready_matching(ready, select.POLLOUT) |
| 62 | if not ready_writers: |
| 63 | raise RuntimeError("no pipes ready for writing") |
| 64 | wr = random.choice(ready_writers) |
| 65 | os.write(wr, MSG) |
| 66 | |
| 67 | ready = p.poll() |
| 68 | ready_readers = find_ready_matching(ready, select.POLLIN) |
| 69 | if not ready_readers: |
| 70 | raise RuntimeError("no pipes ready for reading") |
| 71 | rd = random.choice(ready_readers) |
| 72 | buf = os.read(rd, MSG_LEN) |
| 73 | self.assertEqual(len(buf), MSG_LEN) |
| 74 | bufs.append(buf) |
| 75 | os.close(r2w[rd]) ; os.close( rd ) |
| 76 | p.unregister( r2w[rd] ) |
| 77 | p.unregister( rd ) |
| 78 | writers.remove(r2w[rd]) |
| 79 | |
| 80 | self.assertEqual(bufs, [MSG] * NUM_PIPES) |
| 81 | |
| 82 | def test_poll_unit_tests(self): |
| 83 | # returns NVAL for invalid file descriptor |
nothing calls this directly
no test coverage detected