def test_close(): """ GIVEN Channel is open. WHEN close() is called on a Channel. EXPECT It is closed. """ q = asyncio.Queue() ch = Channel(q) ch.close() assert ch.is_closed()
async def test_capacity_close_unblock(): """ GIVEN Channel is open and full. WHEN Wait for capacity, and close channel. EXPECT Unblocks and returns False. """ q = asyncio.Queue(1) ch = Channel(q) ch.close() assert not await ch.capacity(timeout=0.05) assert not ch.offer('x')
async def test_take_closed(): """ GIVEN Channel is closed. WHEN Take an item. EXPECT Returns None. """ q = asyncio.Queue() ch = Channel(q) ch.close() result = await asyncio.wait_for(ch.take(), timeout=0.05) assert result is None
def test_offer_closed(): """ GIVEN Channel is closed. WHEN Offered an item. EXPECT The item is not added to the queue and offer returns False. """ q = asyncio.Queue() ch = Channel(q) ch.close() x = 'x' assert not ch.offer(x) assert q.empty()
async def test_take_closed_default(): """ GIVEN Channel is closed. WHEN Take an item, and default value is given. EXPECT Returns the given default value. """ q = asyncio.Queue() ch = Channel(q) ch.close() x = 'x' result = await asyncio.wait_for(ch.take(default=x), timeout=0.05) assert result == x
def test_poll_closed(): """ GIVEN Channel is closed but not empty. WHEN Polled for an item. EXPECT Returns an item. """ x = 'x' q = asyncio.Queue() q.put_nowait(x) ch = Channel(q) ch.close() assert ch.poll() == x
async def test_put_closed(): """ GIVEN Closed Channel. WHEN Put an item. EXPECT Item is not added to the Channel and returns False. """ q = asyncio.Queue() ch = Channel(q) ch.close() x = 'x' result = await asyncio.wait_for(ch.put(x), timeout=0.05) assert result == False assert q.empty()