22from pathlib import Path
33import pytest
44from humanloop import Humanloop , FileType , AgentResponse , PromptResponse
5+ from humanloop .error import HumanloopRuntimeError
56
67
78class 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