def test_generate_stream(self):
        """Ensures that generate method calls _stream when stream=True."""
        payload = {"prompt": "Hello"}
        response_mock = Mock()
        response_mock.status_code = 200
        response_mock.iter_lines.return_value = [b'data: {"key": "value"}', b"[DONE]"]
        # Mock the context manager
        stream_cm = MagicMock()
        stream_cm.__enter__.return_value = response_mock
        self.client._client.stream.return_value = stream_cm

        result = list(self.client.generate(prompt="Hello", stream=True))

        assert result == [{"key": "value"}]
Ensures that generate method calls _stream when stream=True.
llama-index-integrations/llms/llama-index-llms-oci-data-science/tests/test_oci_data_science_client.py