def test_adds_item_to_inbox(self, mocker):
     inbox = SyncClientInbox()
     assert inbox.empty()
     item = mocker.MagicMock()
     inbox._put(item)
     assert not inbox.empty()
     assert item in inbox
 def test_check_if_empty(self, mocker):
     inbox = SyncClientInbox()
     assert inbox.empty()
     item = mocker.MagicMock()
     inbox._put(item)
     assert not inbox.empty()
     inbox.get()
     assert inbox.empty()
 def test_removes_item_from_inbox_if_already_there(self, mocker):
     inbox = SyncClientInbox()
     assert inbox.empty()
     item = mocker.MagicMock()
     inbox._put(item)
     assert not inbox.empty()
     retrieved_item = inbox.get()
     assert retrieved_item is item
     assert inbox.empty()
    def test_can_clear_all_items(self, mocker):
        inbox = SyncClientInbox()
        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()
    def test_waits_for_item_to_be_added_if_inbox_empty_in_blocking_mode(
            self, mocker):
        inbox = SyncClientInbox()
        assert inbox.empty()
        item = mocker.MagicMock()

        def insert_item():
            time.sleep(0.01)  # wait before inserting
            inbox._put(item)

        insertion_thread = threading.Thread(target=insert_item)
        insertion_thread.start()

        retrieved_item = inbox.get(block=True)
        assert retrieved_item is item
        assert inbox.empty()
 def test_check_item_is_in_inbox(self, mocker):
     inbox = SyncClientInbox()
     assert inbox.empty()
     item = mocker.MagicMock()
     assert item not in inbox
     inbox._put(item)
     assert item in inbox
 def test_instantiates_empty(self):
     inbox = SyncClientInbox()
     assert inbox.empty()
 def test_get_raises_empty_if_inbox_empty_in_non_blocking_mode(self):
     inbox = SyncClientInbox()
     assert inbox.empty()
     with pytest.raises(InboxEmpty):
         inbox.get(block=False)
 def test_times_out_while_blocking_if_timeout_specified(self, mocker):
     inbox = SyncClientInbox()
     assert inbox.empty()
     with pytest.raises(InboxEmpty):
         inbox.get(block=True, timeout=0.01)