3131 "anthropic_tracer" : ["anthropic" ],
3232 "mistral_tracer" : ["mistralai" ],
3333 "groq_tracer" : ["groq" ],
34+ "oci_tracer" : ["oci" ],
3435 "langchain_callback" : ["langchain" , "langchain_core" , "langchain_community" ],
3536}
3637
3738# Expected patterns for integration modules
3839EXPECTED_PATTERNS = {
3940 "availability_flag" : True , # Should have HAVE_<LIB> flag
40- "helpful_error" : True , # Should give helpful error when instantiating without dependency
41- "graceful_import" : True , # Should import without errors when dependency missing
41+ "helpful_error" : True , # Should give helpful error when instantiating without dependency
42+ "graceful_import" : True , # Should import without errors when dependency missing
4243}
4344
4445
4546def create_import_blocker_script (blocked_packages : List [str ]) -> str :
4647 """Create a script that blocks specific package imports."""
4748 blocked_packages_str = ", " .join (f'"{ pkg } "' for pkg in blocked_packages )
48-
49+
4950 return textwrap .dedent (f"""
5051 import sys
5152 import builtins
@@ -166,36 +167,26 @@ def test_integration_module():
166167def run_integration_test (module_name : str , dependencies : List [str ]) -> Tuple [bool , str ]:
167168 """Run the integration test for a specific module."""
168169 # Create temporary files for the test
169- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .py' , delete = False ) as blocker_file :
170+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .py" , delete = False ) as blocker_file :
170171 blocker_file .write (create_import_blocker_script (dependencies ))
171172 blocker_script = blocker_file .name
172-
173- with tempfile .NamedTemporaryFile (mode = 'w' , suffix = ' .py' , delete = False ) as test_file :
173+
174+ with tempfile .NamedTemporaryFile (mode = "w" , suffix = " .py" , delete = False ) as test_file :
174175 test_file .write (create_integration_test_script (module_name , dependencies ))
175176 test_script = test_file .name
176-
177+
177178 try :
178179 # Run the test in a subprocess
179- cmd = [
180- sys .executable ,
181- '-c' ,
182- f"exec(open('{ blocker_script } ').read()); exec(open('{ test_script } ').read())"
183- ]
184-
185- result = subprocess .run (
186- cmd ,
187- cwd = Path .cwd (),
188- capture_output = True ,
189- text = True ,
190- timeout = 30
191- )
192-
180+ cmd = [sys .executable , "-c" , f"exec(open('{ blocker_script } ').read()); exec(open('{ test_script } ').read())" ]
181+
182+ result = subprocess .run (cmd , cwd = Path .cwd (), capture_output = True , text = True , timeout = 30 )
183+
193184 output = result .stdout
194185 if result .stderr :
195186 output += f"\n STDERR:\n { result .stderr } "
196-
187+
197188 return result .returncode == 0 , output
198-
189+
199190 except subprocess .TimeoutExpired :
200191 return False , "Test timed out"
201192 except Exception as e :
@@ -211,71 +202,71 @@ def run_integration_test(module_name: str, dependencies: List[str]) -> Tuple[boo
211202
212203class TestIntegrationConditionalImports :
213204 """Test class for integration conditional imports."""
214-
205+
215206 def test_all_integrations_handle_missing_dependencies (self ) -> None :
216207 """Test that all integration modules handle missing dependencies correctly."""
217208 print ("\n 🚀 Testing all integration modules for conditional import handling..." )
218-
209+
219210 failed_modules : List [str ] = []
220211 all_results : List [Tuple [str , bool , str ]] = []
221-
212+
222213 for module_name , dependencies in INTEGRATION_DEPENDENCIES .items ():
223- print (f"\n { '=' * 60 } " )
214+ print (f"\n { '=' * 60 } " )
224215 print (f"Testing: { module_name } " )
225216 print (f"Blocked dependencies: { dependencies } " )
226- print ('=' * 60 )
227-
217+ print ("=" * 60 )
218+
228219 success , output = run_integration_test (module_name , dependencies )
229-
220+
230221 print (output )
231-
222+
232223 if not success :
233224 failed_modules .append (module_name )
234225 print (f"❌ FAILED: { module_name } " )
235226 else :
236227 print (f"✅ PASSED: { module_name } " )
237-
228+
238229 all_results .append ((module_name , success , output ))
239-
230+
240231 # Summary
241- print (f"\n { '=' * 60 } " )
232+ print (f"\n { '=' * 60 } " )
242233 print ("SUMMARY" )
243- print ('=' * 60 )
244-
234+ print ("=" * 60 )
235+
245236 total_modules = len (INTEGRATION_DEPENDENCIES )
246237 passed_modules = total_modules - len (failed_modules )
247-
238+
248239 print (f"Total modules tested: { total_modules } " )
249240 print (f"Passed: { passed_modules } " )
250241 print (f"Failed: { len (failed_modules )} " )
251-
242+
252243 if failed_modules :
253244 print (f"\n Failed modules: { ', ' .join (failed_modules )} " )
254-
245+
255246 # Show details for failed modules
256247 for module_name , success , output in all_results :
257248 if not success :
258249 print (f"\n --- { module_name } failure details ---" )
259250 print (output )
260-
251+
261252 # Assert all modules passed
262253 assert len (failed_modules ) == 0 , f"The following modules failed conditional import tests: { failed_modules } "
263-
254+
264255 def test_integration_modules_exist (self ) -> None :
265256 """Test that all expected integration modules exist."""
266257 integrations_dir = Path ("src/openlayer/lib/integrations" )
267-
258+
268259 for module_name in INTEGRATION_DEPENDENCIES .keys ():
269260 module_file = integrations_dir / f"{ module_name } .py"
270261 assert module_file .exists (), f"Integration module { module_name } .py does not exist"
271-
262+
272263 def test_can_import_integrations_when_dependencies_available (self ) -> None :
273264 """Test that integration modules can be imported when their dependencies are available."""
274265 print ("\n 🧪 Testing integration imports when dependencies are available..." )
275-
266+
276267 # This test runs in the normal environment where dependencies may be available
277268 failed_imports : List [str ] = []
278-
269+
279270 for module_name in INTEGRATION_DEPENDENCIES .keys ():
280271 try :
281272 import_path = f"openlayer.lib.integrations.{ module_name } "
@@ -287,29 +278,29 @@ def test_can_import_integrations_when_dependencies_available(self) -> None:
287278 except Exception as e :
288279 print (f"❌ { module_name } import failed with unexpected error: { e } " )
289280 failed_imports .append (module_name )
290-
281+
291282 assert len (failed_imports ) == 0 , f"Unexpected import errors: { failed_imports } "
292283
293284
294285if __name__ == "__main__" :
295286 # Run the tests when called directly
296287 test_instance = TestIntegrationConditionalImports ()
297-
288+
298289 print ("🧪 Running Integration Conditional Import Tests" )
299290 print ("=" * 60 )
300-
291+
301292 try :
302293 test_instance .test_integration_modules_exist ()
303294 print ("✅ All integration modules exist" )
304-
295+
305296 test_instance .test_can_import_integrations_when_dependencies_available ()
306297 print ("✅ Integration imports work when dependencies available" )
307-
298+
308299 test_instance .test_all_integrations_handle_missing_dependencies ()
309300 print ("✅ All integration modules handle missing dependencies correctly" )
310-
301+
311302 print ("\n 🎉 All tests passed!" )
312-
303+
313304 except Exception as e :
314305 print (f"\n 💥 Test failed: { e } " )
315- sys .exit (1 )
306+ sys .exit (1 )
0 commit comments