Ejemplo n.º 1
0
def test_poll_empty():
    """
    GIVEN
        Channel is empty.
    WHEN
        Polled for an item.
    EXPECT
        Returns None
    """
    q = asyncio.Queue()
    ch = Channel(q)
    assert ch.poll() is None
Ejemplo n.º 2
0
def test_poll_empty_given_value():
    """
    GIVEN
        Channel is empty.
    WHEN
        Polled for an item, and a default value is given.
    EXPECT
        Returns the given default value.
    """
    q = asyncio.Queue()
    ch = Channel(q)
    x = 'x'
    assert ch.poll(default=x) == x
Ejemplo n.º 3
0
def test_poll():
    """
    GIVEN
        Channel is not empty.
    WHEN
        Polled for an item.
    EXPECT
        Returns the item.
    """
    x = 'x'
    q = asyncio.Queue()
    q.put_nowait(x)
    ch = Channel(q)
    assert ch.poll() == x
Ejemplo n.º 4
0
async def test_item_unblock():
    """
    GIVEN
        Channel is open and empty.
    WHEN
        Wait for item, and item is added while blocked.
    EXPECT
        Unblocks and returns True.
    """
    q = asyncio.Queue()
    ch = Channel(q)
    x = 'x'
    asyncio.get_running_loop().call_later(0.05, ch.offer, x)
    assert await ch.item(timeout=0.1)
    assert ch.poll() == x