@@ -19,10 +19,13 @@ class TestImportUtils:
1919 """Test the import_mod utility function."""
2020
2121 def test_import_mod_with_module_name (self ):
22- """Test importing specific attribute from a module with missing dependencies."""
23- # Test importing a class that has missing dependencies - should raise ModuleNotFoundError
24- with pytest .raises (ModuleNotFoundError , match = "No module named" ):
25- import_mod ("OpenAIModelComponent" , "openai_chat_model" , "lfx.components.openai" )
22+ """Test importing specific attribute from a module with available dependencies."""
23+ # Test importing a class - should succeed since dependencies are available
24+ result = import_mod ("OpenAIModelComponent" , "openai_chat_model" , "lfx.components.openai" )
25+ assert result is not None
26+ # Should return the OpenAIModelComponent class
27+ assert hasattr (result , "__name__" )
28+ assert result .__name__ == "OpenAIModelComponent"
2629
2730 def test_import_mod_without_module_name (self ):
2831 """Test importing entire module when module_name is None."""
@@ -37,9 +40,9 @@ def test_import_mod_module_not_found(self):
3740 import_mod ("NonExistentComponent" , "nonexistent_module" , "lfx.components.openai" )
3841
3942 def test_import_mod_attribute_not_found (self ):
40- """Test error handling when module has missing dependencies ."""
41- # The openai_chat_model module can't be imported due to missing dependencies
42- with pytest .raises (ModuleNotFoundError , match = "No module named" ):
43+ """Test error handling when attribute doesn't exist in module ."""
44+ # Test importing a non-existent attribute from a valid module
45+ with pytest .raises (AttributeError ):
4346 import_mod ("NonExistentComponent" , "openai_chat_model" , "lfx.components.openai" )
4447
4548
@@ -94,13 +97,15 @@ def test_category_module_dynamic_import(self):
9497 assert "OpenAIModelComponent" in openai_components .__all__
9598 assert "OpenAIEmbeddingsComponent" in openai_components .__all__
9699
97- # Access component - this should raise AttributeError due to missing langchain-openai
98- with pytest .raises (AttributeError , match = "Could not import 'OpenAIModelComponent'" ):
99- _ = openai_components .OpenAIModelComponent
100+ # Access component - this should succeed since dependencies are available
101+ model_component = openai_components .OpenAIModelComponent
102+ assert model_component is not None
103+ assert hasattr (model_component , "__name__" )
104+ assert model_component .__name__ == "OpenAIModelComponent"
100105
101- # Test that the error is properly cached - second access should also fail
102- with pytest . raises ( AttributeError , match = "Could not import ' OpenAIModelComponent'" ):
103- _ = openai_components . OpenAIModelComponent
106+ # Test that the component is properly cached - second access should return same object
107+ model_component_2 = openai_components . OpenAIModelComponent
108+ assert model_component_2 is model_component
104109
105110 def test_category_module_dir (self ):
106111 """Test __dir__ functionality for category modules."""
@@ -215,9 +220,11 @@ def test_type_checking_imports(self):
215220 assert "SearchComponent" in searchapi_components .__all__
216221 assert "SearchComponent" in searchapi_components ._dynamic_imports
217222
218- # Accessing should trigger dynamic import - may fail due to missing dependencies
219- with pytest .raises (AttributeError , match = r"Could not import.*SearchComponent" ):
220- _ = searchapi_components .SearchComponent
223+ # Accessing should trigger dynamic import - should succeed with dependencies
224+ search_component = searchapi_components .SearchComponent
225+ assert search_component is not None
226+ assert hasattr (search_component , "__name__" )
227+ assert search_component .__name__ == "SearchComponent"
221228
222229
223230class TestPerformanceCharacteristics :
@@ -227,21 +234,24 @@ def test_lazy_loading_performance(self):
227234 """Test that components can be accessed and cached properly."""
228235 from lfx .components import chroma as chromamodules
229236
230- # Test that we can access a component
231- with pytest .raises (AttributeError , match = r"Could not import.*ChromaVectorStoreComponent" ):
232- chromamodules .ChromaVectorStoreComponent # noqa: B018
237+ # Test that we can access a component - should succeed with dependencies
238+ chroma_component = chromamodules .ChromaVectorStoreComponent
239+ assert chroma_component is not None
240+ assert hasattr (chroma_component , "__name__" )
241+ assert chroma_component .__name__ == "ChromaVectorStoreComponent"
233242
234243 def test_caching_behavior (self ):
235244 """Test that components are cached after first access."""
236245 from lfx .components import models
237246
238- # EmbeddingModelComponent should raise AttributeError due to missing dependencies
239- with pytest .raises (AttributeError , match = r"Could not import.*EmbeddingModelComponent" ):
240- _ = models .EmbeddingModelComponent
247+ # EmbeddingModelComponent should succeed with dependencies
248+ embedding_component = models .EmbeddingModelComponent
249+ assert embedding_component is not None
250+ assert hasattr (embedding_component , "__name__" )
241251
242- # Test that error is cached - subsequent access should also fail
243- with pytest . raises ( AttributeError , match = r"Could not import.* EmbeddingModelComponent" ):
244- _ = models . EmbeddingModelComponent
252+ # Test that component is cached - subsequent access should return same object
253+ embedding_component_2 = models . EmbeddingModelComponent
254+ assert embedding_component_2 is embedding_component
245255
246256 def test_memory_usage_multiple_accesses (self ):
247257 """Test memory behavior with multiple component accesses."""
@@ -282,23 +292,26 @@ def test_platform_specific_components(self):
282292 """Test platform-specific component handling (like NVIDIA Windows components)."""
283293 import lfx .components .nvidia as nvidia_components
284294
285- # NVIDIAModelComponent should raise AttributeError due to missing langchain-nvidia-ai-endpoints dependency
286- with pytest .raises (AttributeError , match = r"Could not import.*NVIDIAModelComponent" ):
287- _ = nvidia_components .NVIDIAModelComponent
295+ # NVIDIAModelComponent should succeed with dependencies
296+ nvidia_component = nvidia_components .NVIDIAModelComponent
297+ assert nvidia_component is not None
298+ assert hasattr (nvidia_component , "__name__" )
299+ assert nvidia_component .__name__ == "NVIDIAModelComponent"
288300
289- # Test that __all__ still works correctly despite import failures
301+ # Test that __all__ works correctly
290302 assert "NVIDIAModelComponent" in nvidia_components .__all__
291303
292304 def test_import_structure_integrity (self ):
293305 """Test that the import structure maintains integrity."""
294306 from lfx import components
295307
296308 # Test that we can access nested components through the hierarchy
297- # OpenAI component requires langchain_openai which isn't installed
298- with pytest .raises (AttributeError , match = r"Could not import.*OpenAIModelComponent" ):
299- _ = components .openai .OpenAIModelComponent
309+ # OpenAI component should succeed with dependencies
310+ openai_component = components .openai .OpenAIModelComponent
311+ assert openai_component is not None
312+ assert hasattr (openai_component , "__name__" )
300313
301- # APIRequestComponent should work now that validators is installed
314+ # APIRequestComponent should work with dependencies
302315 api_component = components .data .APIRequestComponent
303316 assert api_component is not None
304317
0 commit comments