예제 #1
0
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()
예제 #2
0
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')
예제 #3
0
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
예제 #4
0
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()
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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()