コード例 #1
0
 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
コード例 #2
0
 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
コード例 #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()
     await asyncio.sleep(0.01
                         )  # Do this to prevent RuntimeWarning from janus
コード例 #4
0
    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
コード例 #5
0
    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()
コード例 #6
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

        await asyncio.sleep(0.01
                            )  # Do this to prevent RuntimeWarning from janus