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
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
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
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()
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