langflow/tests/test_loading.py
Gabriel Luiz Freitas Almeida b0308336c2
Fix State Service not loading when using load_flow_from_json (#1661)
* Refactor test_loading.py to improve code readability and maintainability

* Refactor code in test_template.py, __main__.py, and utils.py to improve code readability and maintainability

* Fix logger.configure() to disable logging when disable flag is True

* Refactor validate_icon function to use emoji library for emoji validation in model.py

* Refactor import statements in base.py files to improve code organization and maintainability

* Refactor state_manager.py to handle error when getting state service and use InMemoryStateService as fallback

* Refactor load_flow_from_json function in load.py to configure logs and load services

* Add test_run_flow_from_json_object function to test_loading.py

* Refactor langflow.processing.process.py and langflow.schema.graph.py

* Set all streaming to false in run_flow_from_json function

* Refactor import statements in base.py files to improve code organization and maintainability

* Refactor arun function in base.py to handle event loop and async execution

* Add docstring to run_flow_from_json

* Refactor import statements in base.py files to use logger in langflow interface

* Refactor build method in ChatOutput and TextInput classes to use build_with_record

* Refactor import statements in base.py files to improve code organization and maintainability

* Refactor import statements in PythonREPLTool.py for improved code organization and maintainability

* Refactor build method in TextOutput class to include optional record_template parameter

* Refactor build method in ChatComponent class to include build_no_record method

* Refactor input_value parameter in TextInput build method to use Text type

* Refactor import statements in FlowTool.py for improved code organization and maintainability

* Bump langflow-base version to 0.0.25 and add asyncer dependency

* Refactor code in multiple files for improved organization and maintainability

* Refactor import statements in multiple files for improved code organization and maintainability
2024-04-10 11:56:37 -03:00

42 lines
1.5 KiB
Python

import pytest
from langflow.graph import Graph
from langflow.graph.schema import RunOutputs
from langflow.initial_setup.setup import load_starter_projects
from langflow.processing.load import load_flow_from_json, run_flow_from_json
@pytest.mark.noclient
def test_load_flow_from_json():
"""Test loading a flow from a json file"""
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH)
assert loaded is not None
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"}}
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH, tweaks=tweaks)
assert loaded is not None
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())
project = projects[0]
loaded = load_flow_from_json(project)
assert loaded is not None
assert isinstance(loaded, Graph)
@pytest.mark.noclient
def test_run_flow_from_json_object():
"""Test loading a flow from a json file and applying tweaks"""
_, projects = zip(*load_starter_projects())
project = projects[0]
results = run_flow_from_json(project, input_value="test")
assert results is not None
assert all(isinstance(result, RunOutputs) for result in results)