mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-25 10:06:43 +08:00
fix: Make failing tests environment aware
This commit is contained in:
@ -209,17 +209,25 @@ class TestComponentDynamicImports:
|
||||
"""Test that TYPE_CHECKING imports work correctly with dynamic loading."""
|
||||
# This test ensures that imports in TYPE_CHECKING blocks
|
||||
# work correctly with the dynamic import system
|
||||
import importlib.util
|
||||
|
||||
import lfx.components.searchapi as searchapi_components
|
||||
|
||||
# Components should be available for dynamic loading
|
||||
assert "SearchComponent" in searchapi_components.__all__
|
||||
assert "SearchComponent" in searchapi_components._dynamic_imports
|
||||
|
||||
# langchain-community is now transitively provided by lfx (via OpenDsStar),
|
||||
# so accessing SearchComponent triggers a successful dynamic import.
|
||||
component = searchapi_components.SearchComponent
|
||||
assert component is not None
|
||||
assert hasattr(component, "__init__")
|
||||
# SearchComponent imports from langchain_community at module-import time.
|
||||
# If that package is present in this environment (e.g. transitively via
|
||||
# OpenDsStar), the dynamic import should succeed; otherwise it should
|
||||
# raise AttributeError wrapping the ImportError.
|
||||
if importlib.util.find_spec("langchain_community") is not None:
|
||||
component = searchapi_components.SearchComponent
|
||||
assert component is not None
|
||||
assert hasattr(component, "__init__")
|
||||
else:
|
||||
with pytest.raises(AttributeError, match=r"Could not import.*SearchComponent"):
|
||||
_ = searchapi_components.SearchComponent
|
||||
|
||||
|
||||
class TestPerformanceCharacteristics:
|
||||
|
||||
@ -719,12 +719,18 @@ class TestStarterProjects:
|
||||
def test_simple_agent_has_community(self, simple_agent_flow):
|
||||
"""Simple Agent's URLComponent imports langchain_community.
|
||||
|
||||
lfx now provides langchain-community transitively (via OpenDsStar),
|
||||
so it is filtered out of generated requirements as already-provided.
|
||||
When lfx provides langchain-community transitively (e.g. via
|
||||
OpenDsStar in some environments) it is filtered out of generated
|
||||
requirements as already-provided; otherwise it should appear.
|
||||
"""
|
||||
from lfx.utils.flow_requirements import _get_lfx_provided_imports
|
||||
|
||||
result = generate_requirements_from_flow(simple_agent_flow, pin_versions=False)
|
||||
assert "lfx" in result
|
||||
assert "langchain-community" not in result
|
||||
if "langchain_community" in _get_lfx_provided_imports():
|
||||
assert "langchain-community" not in result
|
||||
else:
|
||||
assert "langchain-community" in result
|
||||
|
||||
def test_basic_prompting_from_file(self):
|
||||
"""Test the file-based API.
|
||||
|
||||
Reference in New Issue
Block a user