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