MCPcopy Index your code
hub / github.com/python/cpython / test_poll1

Method test_poll1

Lib/test/test_poll.py:33–80  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

31class 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

Callers

nothing calls this directly

Calls 13

choiceMethod · 0.80
find_ready_matchingFunction · 0.70
pollMethod · 0.45
pipeMethod · 0.45
registerMethod · 0.45
modifyMethod · 0.45
appendMethod · 0.45
writeMethod · 0.45
readMethod · 0.45
assertEqualMethod · 0.45
closeMethod · 0.45
unregisterMethod · 0.45

Tested by

no test coverage detected