def test_peek_back_when_items_returns_expected_front_of_queue(self):
        # Arrange
        queue = Queue()
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")

        # Act, Assert
        assert queue.peek_back() == "C"
    def test_put_nowait(self):
        # Arrange
        queue = Queue()

        # Act
        queue.put_nowait("A")

        # Assert
        assert queue.qsize() == 1
        assert not queue.empty()
    def test_put_nowait(self):
        # Arrange
        queue = Queue()

        # Act
        queue.put_nowait("A")

        # Assert
        self.assertEqual(1, queue.qsize())
        self.assertFalse(queue.empty())
    def test_get_nowait(self):
        # Arrange
        queue = Queue()
        queue.put_nowait("A")

        # Act
        item = queue.get_nowait()

        # Assert
        assert queue.empty()
        assert item == "A"
    def test_peek_index_when_items_returns_expected_front_of_queue(self):
        # Arrange
        queue = Queue()
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")

        # Act, Assert
        assert queue.peek_index(-1) == "A"
        assert queue.peek_index(1) == "B"
        assert queue.peek_index(0) == "C"
    def test_get_nowait(self):
        # Arrange
        queue = Queue()
        queue.put_nowait("A")

        # Act
        item = queue.get_nowait()

        # Assert
        self.assertEqual(0, queue.qsize())
        self.assertEqual("A", item)
        async def run_test():
            # Arrange
            queue = Queue()
            queue.put_nowait("A")

            # Act
            item = await queue.get()

            # Assert
            self.assertEqual(0, queue.qsize())
            self.assertEqual("A", item)
        async def run_test():
            # Arrange
            queue = Queue()
            queue.put_nowait("A")

            # Act
            item = await queue.get()

            # Assert
            assert queue.empty()
            assert item == "A"
    def test_as_list_when_items_returns_expected_list(self):
        # Arrange
        queue = Queue()
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")

        # Act
        result = queue.to_list()

        # Assert
        assert result == ["C", "B", "A"]
        assert queue.get_nowait() == "A"
        assert result == ["C", "B", "A"]  # <-- confirm was copy
    def test_put_nowait_onto_queue_at_maxsize_raises_queue_full(self):
        # Arrange
        queue = Queue(maxsize=5)

        # Act
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")
        queue.put_nowait("D")
        queue.put_nowait("E")

        # Assert
        with pytest.raises(asyncio.QueueFull):
            queue.put_nowait("F")
    def test_put_to_maxlen_makes_queue_full(self):
        # Arrange
        queue = Queue(maxsize=5)

        # Act
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")
        queue.put_nowait("D")
        queue.put_nowait("E")

        # Assert
        assert queue.qsize() == 5
        assert queue.full()
    def test_put_nowait_multiple_items(self):
        # Arrange
        queue = Queue()

        # Act
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")
        queue.put_nowait("D")
        queue.put_nowait("E")

        # Assert
        assert queue.qsize() == 5
        assert not queue.empty()
Esempio n. 13
0
    def test_put_to_maxlen_makes_queue_full(self):
        # Arrange
        queue = Queue(maxsize=5)

        # Act
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")
        queue.put_nowait("D")
        queue.put_nowait("E")

        # Assert
        self.assertEqual(5, queue.qsize())
        self.assertTrue(queue.full())
Esempio n. 14
0
    def test_put_nowait_multiple_items(self):
        # Arrange
        queue = Queue()

        # Act
        queue.put_nowait("A")
        queue.put_nowait("B")
        queue.put_nowait("C")
        queue.put_nowait("D")
        queue.put_nowait("E")

        # Assert
        self.assertEqual(5, queue.qsize())
        self.assertFalse(queue.empty())