refactor: add fixtures for client in test files to speed them up (#3490)
refactor: Add fixtures for client in test files to speed them up
This commit is contained in:
parent
091baf7f33
commit
6d048b2d2c
9 changed files with 44 additions and 50 deletions
|
|
@ -1,47 +0,0 @@
|
|||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from langflow.graph import Graph
|
||||
|
||||
|
||||
def get_graph(_type="basic"):
|
||||
"""Get a graph from a json file"""
|
||||
if _type == "basic":
|
||||
path = pytest.BASIC_EXAMPLE_PATH
|
||||
elif _type == "complex":
|
||||
path = pytest.COMPLEX_EXAMPLE_PATH
|
||||
elif _type == "openapi":
|
||||
path = pytest.OPENAPI_EXAMPLE_PATH
|
||||
|
||||
with open(path, "r") as f:
|
||||
flow_graph = json.load(f)
|
||||
return flow_graph["data"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def basic_data_graph():
|
||||
return get_graph()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def complex_data_graph():
|
||||
return get_graph("complex")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def openapi_data_graph():
|
||||
return get_graph("openapi")
|
||||
|
||||
|
||||
def langchain_objects_are_equal(obj1, obj2):
|
||||
return str(obj1) == str(obj2)
|
||||
|
||||
|
||||
# Test build_graph
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_graph(client, basic_data_graph):
|
||||
graph = Graph.from_payload(basic_data_graph)
|
||||
assert graph is not None
|
||||
assert len(graph.vertices) == len(basic_data_graph["nodes"])
|
||||
assert len(graph.edges) == len(basic_data_graph["edges"])
|
||||
|
|
@ -1,8 +1,14 @@
|
|||
import pytest
|
||||
from langchain_core.documents import Document
|
||||
|
||||
from langflow.schema import Data
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
def test_data_initialization():
|
||||
record = Data(text_key="msg", data={"msg": "Hello, World!", "extra": "value"})
|
||||
assert record.msg == "Hello, World!"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
from langflow.components import prototypes
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
def test_python_function_component():
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ from langflow.template.frontend_node.base import FrontendNode
|
|||
from langflow.template.template.base import Template
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_template_field() -> Input:
|
||||
return Input(name="test_field", field_type="str")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
from langflow.components import helpers
|
||||
from langflow.custom.utils import build_custom_component_template
|
||||
from langflow.schema import Data
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
# def test_update_data_component():
|
||||
# # Arrange
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ from langflow.initial_setup.setup import load_starter_projects
|
|||
from langflow.load import load_flow_from_json
|
||||
|
||||
|
||||
@pytest.mark.noclient
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
def test_load_flow_from_json():
|
||||
"""Test loading a flow from a json file"""
|
||||
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH)
|
||||
|
|
@ -13,7 +17,6 @@ def test_load_flow_from_json():
|
|||
assert isinstance(loaded, Graph)
|
||||
|
||||
|
||||
@pytest.mark.noclient
|
||||
def test_load_flow_from_json_with_tweaks():
|
||||
"""Test loading a flow from a json file and applying tweaks"""
|
||||
tweaks = {"dndnode_82": {"model_name": "gpt-3.5-turbo-16k-0613"}}
|
||||
|
|
@ -22,7 +25,6 @@ def test_load_flow_from_json_with_tweaks():
|
|||
assert isinstance(loaded, Graph)
|
||||
|
||||
|
||||
@pytest.mark.noclient
|
||||
def test_load_flow_from_json_object():
|
||||
"""Test loading a flow from a json file and applying tweaks"""
|
||||
_, projects = zip(*load_starter_projects())
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ from unittest.mock import patch
|
|||
from langflow.logging.logger import SizedLogBuffer
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sized_log_buffer():
|
||||
return SizedLogBuffer()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ from langflow.utils.util import build_template_from_function, get_base_classes,
|
|||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
# Dummy classes for testing purposes
|
||||
class Parent(BaseModel):
|
||||
"""Parent Class"""
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ from requests.exceptions import MissingSchema
|
|||
from langflow.utils.validate import create_function, execute_function, extract_function_name, validate_code
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
pass
|
||||
|
||||
|
||||
def test_create_function():
|
||||
code = """
|
||||
from pathlib import Path
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue