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:
Gabriel Luiz Freitas Almeida 2024-08-22 16:08:47 -03:00 committed by GitHub
commit 6d048b2d2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 44 additions and 50 deletions

View file

@ -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"])

View file

@ -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!"

View file

@ -1,4 +1,10 @@
from langflow.components import prototypes
import pytest
@pytest.fixture
def client():
pass
def test_python_function_component():

View file

@ -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")

View file

@ -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

View file

@ -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())

View file

@ -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()

View file

@ -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"""

View file

@ -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