Skip to content

Commit 1d3268e

Browse files
committed
test(perplexity): add integration tests for all components
Add @pytest.mark.integration-guarded end-to-end tests (sync + async) for: - PerplexityChatGenerator - PerplexityDocumentEmbedder - PerplexityTextEmbedder PerplexityWebSearch integration tests already exist. All integration tests are skipped unless PERPLEXITY_API_KEY is set so they won't impact regular unit-test CI runs.
1 parent bf28eec commit 1d3268e

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

integrations/perplexity/tests/test_perplexity_chat_generator.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import os
56
from datetime import datetime, timezone
67
from unittest.mock import patch
78

@@ -199,3 +200,27 @@ def test_default_headers_include_perplexity_attribution(self):
199200
assert component.client.default_headers["test-header"] == "test-value"
200201
assert component.async_client.default_headers["X-Pplx-Integration"].startswith("haystack/")
201202
assert component.async_client.default_headers["test-header"] == "test-value"
203+
204+
205+
@pytest.mark.skipif(
206+
not os.environ.get("PERPLEXITY_API_KEY"),
207+
reason="Export PERPLEXITY_API_KEY to run integration tests.",
208+
)
209+
@pytest.mark.integration
210+
class TestPerplexityChatGeneratorInference:
211+
def test_live_run(self):
212+
chat_messages = [ChatMessage.from_user("What's the capital of France? Reply in one word.")]
213+
component = PerplexityChatGenerator()
214+
results = component.run(chat_messages)
215+
assert len(results["replies"]) == 1
216+
message: ChatMessage = results["replies"][0]
217+
assert "Paris" in message.text
218+
219+
@pytest.mark.asyncio
220+
async def test_live_run_async(self):
221+
chat_messages = [ChatMessage.from_user("What's the capital of France? Reply in one word.")]
222+
component = PerplexityChatGenerator()
223+
results = await component.run_async(chat_messages)
224+
assert len(results["replies"]) == 1
225+
message: ChatMessage = results["replies"][0]
226+
assert "Paris" in message.text

integrations/perplexity/tests/test_perplexity_document_embedder.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import json
6+
import os
67

78
import httpx
89
import pytest
@@ -248,3 +249,40 @@ def test_run_wrong_input_format(self):
248249
embedder.run(documents=[1, 2, 3])
249250

250251
assert embedder.run(documents=[]) == {"documents": [], "meta": {}}
252+
253+
254+
@pytest.mark.skipif(
255+
not os.environ.get("PERPLEXITY_API_KEY"),
256+
reason="Export PERPLEXITY_API_KEY to run integration tests.",
257+
)
258+
@pytest.mark.integration
259+
class TestPerplexityDocumentEmbedderInference:
260+
def test_live_run(self):
261+
docs = [
262+
Document(content="The capital of France is Paris."),
263+
Document(content="The capital of Germany is Berlin."),
264+
]
265+
embedder = PerplexityDocumentEmbedder()
266+
result = embedder.run(documents=docs)
267+
268+
embedded_docs = result["documents"]
269+
assert len(embedded_docs) == len(docs)
270+
for doc in embedded_docs:
271+
assert isinstance(doc.embedding, list)
272+
assert len(doc.embedding) > 0
273+
assert all(isinstance(x, float) for x in doc.embedding)
274+
275+
@pytest.mark.asyncio
276+
async def test_live_run_async(self):
277+
docs = [
278+
Document(content="The capital of France is Paris."),
279+
Document(content="The capital of Germany is Berlin."),
280+
]
281+
embedder = PerplexityDocumentEmbedder()
282+
result = await embedder.run_async(documents=docs)
283+
284+
embedded_docs = result["documents"]
285+
assert len(embedded_docs) == len(docs)
286+
for doc in embedded_docs:
287+
assert isinstance(doc.embedding, list)
288+
assert len(doc.embedding) > 0

integrations/perplexity/tests/test_perplexity_text_embedder.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
import json
6+
import os
67

78
import httpx
89
import pytest
@@ -186,3 +187,28 @@ def test_run_wrong_input_format(self):
186187

187188
with pytest.raises(TypeError, match=match_error_msg):
188189
embedder.run(text=["text_snippet_1", "text_snippet_2"])
190+
191+
192+
@pytest.mark.skipif(
193+
not os.environ.get("PERPLEXITY_API_KEY"),
194+
reason="Export PERPLEXITY_API_KEY to run integration tests.",
195+
)
196+
@pytest.mark.integration
197+
class TestPerplexityTextEmbedderInference:
198+
def test_live_run(self):
199+
text = "The capital of France is Paris."
200+
embedder = PerplexityTextEmbedder()
201+
result = embedder.run(text=text)
202+
203+
assert isinstance(result["embedding"], list)
204+
assert len(result["embedding"]) > 0
205+
assert all(isinstance(x, float) for x in result["embedding"])
206+
207+
@pytest.mark.asyncio
208+
async def test_live_run_async(self):
209+
text = "The capital of France is Paris."
210+
embedder = PerplexityTextEmbedder()
211+
result = await embedder.run_async(text=text)
212+
213+
assert isinstance(result["embedding"], list)
214+
assert len(result["embedding"]) > 0

0 commit comments

Comments
 (0)