async def test_select_push(self): """Pushing on two channels should return the one with room""" sel = Selector() async with Channel(1) as chan1, Channel(1) as chan2: # Push to C2 first sel.push(chan1, 10) sel.push(chan2, 20) await chan1.push(11) val = await sel.gather() await chan1.close() self.assertEqual(val, (1, True)) self.assertEqual(await chan1.pop(), 11) self.assertEqual(await chan1.pop(), None) self.assertEqual(await chan2.pop(), 20)
async def test_select_both_push(self): """Push and popping should perform the first available op""" sel1, sel2 = Selector(), Selector() async with Channel(1) as chan1, Channel(1) as chan2: # c1 will be empty (cannot pop) sel1.pop(chan1) sel1.push(chan2, 10) val = await sel1.gather() self.assertEqual(val, (1, True)) # c2 will be empty (cannot pop) self.assertEqual(await chan2.pop(), 10) sel2.push(chan1, 20) sel2.pop(chan2) val = await sel2.gather() self.assertEqual(val, (0, True))