Skip to content

Commit f72fda0

Browse files
committed
add tests for overloading call and log operations on agents and prompts
1 parent d703478 commit f72fda0

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,13 @@ def api_keys() -> APIKeys:
191191

192192

193193
@pytest.fixture(scope="session")
194-
def humanloop_client(api_keys: APIKeys) -> Humanloop:
194+
def humanloop_client(request, api_keys: APIKeys) -> Humanloop:
195+
"""Create a Humanloop client for testing."""
196+
use_local_files = getattr(request, "param", False)
195197
return Humanloop(
196198
api_key=api_keys.humanloop,
197199
base_url="http://localhost:80/v5/",
200+
use_local_files=use_local_files
198201
)
199202

200203

tests/sync/test_sync.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
import pytest
44
from humanloop import Humanloop, FileType, AgentResponse, PromptResponse
5+
from humanloop.error import HumanloopRuntimeError
56

67

78
class SyncableFile(NamedTuple):
@@ -94,3 +95,91 @@ def test_pull_basic(humanloop_client: Humanloop, test_file_structure: List[Synca
9495
# Verify it's not empty
9596
content = local_path.read_text()
9697
assert content, f"File at {local_path} should not be empty"
98+
99+
@pytest.mark.parametrize("humanloop_client", [True], indirect=True)
100+
def test_overload_with_local_files(humanloop_client: Humanloop, test_file_structure: List[SyncableFile], cleanup_local_files):
101+
"""Test that overload_with_local_files correctly handles local files.
102+
103+
Flow:
104+
1. Create files in remote (via test_file_structure fixture)
105+
2. Pull files locally
106+
3. Test using the pulled files
107+
"""
108+
# First pull the files locally
109+
humanloop_client.pull()
110+
111+
# Test using the pulled files
112+
test_file = test_file_structure[0] # Use the first test file
113+
extension = f".{test_file.type}"
114+
local_path = Path("humanloop") / f"{test_file.path}{extension}"
115+
116+
# Verify the file was pulled correctly
117+
assert local_path.exists(), f"Expected pulled file at {local_path}"
118+
assert local_path.parent.exists(), f"Expected directory at {local_path.parent}"
119+
120+
# Test call with pulled file
121+
if test_file.type == "prompt":
122+
response = humanloop_client.prompts.call(path=test_file.path, messages=[{"role": "user", "content": "Testing"}])
123+
assert response is not None
124+
elif test_file.type == "agent":
125+
response = humanloop_client.agents.call(path=test_file.path, messages=[{"role": "user", "content": "Testing"}])
126+
assert response is not None
127+
128+
# Test with invalid path
129+
with pytest.raises(HumanloopRuntimeError):
130+
if test_file.type == "prompt":
131+
humanloop_client.prompts.call(path="invalid/path")
132+
elif test_file.type == "agent":
133+
humanloop_client.agents.call(path="invalid/path")
134+
135+
@pytest.mark.parametrize("humanloop_client", [True], indirect=True)
136+
def test_overload_log_with_local_files(humanloop_client: Humanloop, test_file_structure: List[SyncableFile], cleanup_local_files):
137+
"""Test that overload_with_local_files correctly handles local files for log operations.
138+
139+
Flow:
140+
1. Create files in remote (via test_file_structure fixture)
141+
2. Pull files locally
142+
3. Test logging using the pulled files
143+
"""
144+
# First pull the files locally
145+
humanloop_client.pull()
146+
147+
# Test using the pulled files
148+
test_file = test_file_structure[0] # Use the first test file
149+
extension = f".{test_file.type}"
150+
local_path = Path("humanloop") / f"{test_file.path}{extension}"
151+
152+
# Verify the file was pulled correctly
153+
assert local_path.exists(), f"Expected pulled file at {local_path}"
154+
assert local_path.parent.exists(), f"Expected directory at {local_path.parent}"
155+
156+
# Test log with pulled file
157+
if test_file.type == "prompt":
158+
response = humanloop_client.prompts.log(
159+
path=test_file.path,
160+
messages=[{"role": "user", "content": "Testing"}],
161+
output="Test response"
162+
)
163+
assert response is not None
164+
elif test_file.type == "agent":
165+
response = humanloop_client.agents.log(
166+
path=test_file.path,
167+
messages=[{"role": "user", "content": "Testing"}],
168+
output="Test response"
169+
)
170+
assert response is not None
171+
172+
# Test with invalid path
173+
with pytest.raises(HumanloopRuntimeError):
174+
if test_file.type == "prompt":
175+
humanloop_client.prompts.log(
176+
path="invalid/path",
177+
messages=[{"role": "user", "content": "Testing"}],
178+
output="Test response"
179+
)
180+
elif test_file.type == "agent":
181+
humanloop_client.agents.log(
182+
path="invalid/path",
183+
messages=[{"role": "user", "content": "Testing"}],
184+
output="Test response"
185+
)

0 commit comments

Comments
 (0)