MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_devpoll1

Method test_devpoll1

Lib/test/test_devpoll.py:24–72  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

lenFunction · 0.85
choiceMethod · 0.80
find_ready_matchingFunction · 0.70
pipeMethod · 0.45
registerMethod · 0.45
modifyMethod · 0.45
appendMethod · 0.45
pollMethod · 0.45
failMethod · 0.45
writeMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected