def test_check_item_is_in_inbox(self, mocker):
     inbox = AsyncClientInbox()
     assert inbox.empty()
     item = mocker.MagicMock()
     assert item not in inbox
     inbox._put(item)
     assert item in inbox
 def test_adds_item_to_inbox(self, mocker):
     inbox = AsyncClientInbox()
     assert inbox.empty()
     item = mocker.MagicMock()
     inbox._put(item)
     assert not inbox.empty()
     assert item in inbox
Exemplo n.º 3
0
 async def test_can_check_if_empty(self, mocker):
     inbox = AsyncClientInbox()
     assert inbox.empty()
     inbox._put(mocker.MagicMock())
     assert not inbox.empty()
     await inbox.get()
     assert inbox.empty()
 async def test_can_check_if_empty(self, mocker):
     inbox = AsyncClientInbox()
     assert inbox.empty()
     inbox._put(mocker.MagicMock())
     assert not inbox.empty()
     await inbox.get()
     assert inbox.empty()
     await asyncio.sleep(0.01)  # Do this to prevent RuntimeWarning from janus
Exemplo n.º 5
0
 async def test_get_removes_item_from_inbox_if_already_there(self, mocker):
     inbox = AsyncClientInbox()
     assert inbox.empty()
     item = mocker.MagicMock()
     inbox._put(item)
     assert not inbox.empty()
     retrieved_item = await inbox.get()
     assert retrieved_item is item
     assert inbox.empty()
    async def test_removes_item_from_inbox_if_already_there(self, mocker):
        inbox = AsyncClientInbox()
        assert inbox.empty()
        item = mocker.MagicMock()
        inbox._put(item)
        assert not inbox.empty()
        retrieved_item = await inbox.get()
        assert retrieved_item is item
        assert inbox.empty()

        await asyncio.sleep(0.01)  # Do this to prevent RuntimeWarning from janus
    def test_can_clear_all_items(self, mocker):
        inbox = AsyncClientInbox()
        item1 = mocker.MagicMock()
        item2 = mocker.MagicMock()
        item3 = mocker.MagicMock()
        inbox._put(item1)
        inbox._put(item2)
        inbox._put(item3)
        assert not inbox.empty()

        inbox.clear()
        assert inbox.empty()
Exemplo n.º 8
0
    async def test_operates_according_to_FIFO(self, mocker):
        inbox = AsyncClientInbox()
        item1 = mocker.MagicMock()
        item2 = mocker.MagicMock()
        item3 = mocker.MagicMock()
        inbox._put(item1)
        inbox._put(item2)
        inbox._put(item3)

        assert await inbox.get() is item1
        assert await inbox.get() is item2
        assert await inbox.get() is item3
    async def test_get_waits_for_item_to_be_added_if_inbox_empty(self, mocker):
        inbox = AsyncClientInbox()
        assert inbox.empty()
        item = mocker.MagicMock()

        async def wait_for_item():
            retrieved_item = await inbox.get()
            assert retrieved_item is item

        async def insert_item():
            await asyncio.sleep(1)  # wait before adding item to ensure the above coroutine is first
            inbox._put(item)

        await asyncio.gather(wait_for_item(), insert_item())
    async def test_operates_according_to_FIFO(self, mocker):
        inbox = AsyncClientInbox()
        item1 = mocker.MagicMock()
        item2 = mocker.MagicMock()
        item3 = mocker.MagicMock()
        inbox._put(item1)
        inbox._put(item2)
        inbox._put(item3)

        assert await inbox.get() is item1
        assert await inbox.get() is item2
        assert await inbox.get() is item3

        await asyncio.sleep(0.01)  # Do this to prevent RuntimeWarning from janus
 def test_instantiates_empty(self):
     inbox = AsyncClientInbox()
     assert inbox.empty()