langflow/tests/test_loading.py
Gabriel Luiz Freitas Almeida d0aa3261f1 🐛 fix(flows.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(schemas.py): change json.dumps to orjson_dumps for improved performance and compatibility with orjson library
🐛 fix(utils.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(loading.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(utils.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(vector_store.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(types.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(process.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
 feat(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics
 feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port

🔧 fix(base.py): import orjson instead of json to improve performance and compatibility
🔧 fix(frontend_node/llms.py): use orjson_dumps instead of json.dumps to improve performance and compatibility
🔧 fix(frontend_node/utilities.py): use orjson_dumps instead of json.dumps to improve performance and compatibility
🔧 fix(test_cache.py): import orjson and use orjson_dumps instead of json.dumps to improve performance and compatibility

🔧 fix(test_database.py): import correct json encoder and decoder functions to fix import errors
🔧 fix(test_database.py): replace json.dumps and json.loads with orjson_dumps and orjson.loads for better performance and compatibility
🔧 fix(test_loading.py): remove unused import statement
2023-08-22 11:04:41 -03:00

35 lines
1.1 KiB
Python

import json
import pytest
from langchain.chains.base import Chain
from langflow.processing.process import load_flow_from_json
from langflow.graph import Graph
from langflow.utils.payload import get_root_node
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, Chain)
def test_load_flow_from_json_with_tweaks():
"""Test loading a flow from a json file and applying tweaks"""
tweaks = {"dndnode_82": {"model_name": "test model"}}
loaded = load_flow_from_json(pytest.BASIC_EXAMPLE_PATH, tweaks=tweaks)
assert loaded is not None
assert isinstance(loaded, Chain)
assert loaded.llm.model_name == "test model"
def test_get_root_node():
with open(pytest.BASIC_EXAMPLE_PATH, "r") as f:
flow_graph = json.load(f)
data_graph = flow_graph["data"]
nodes = data_graph["nodes"]
edges = data_graph["edges"]
graph = Graph(nodes, edges)
root = get_root_node(graph)
assert root is not None
assert hasattr(root, "id")
assert hasattr(root, "data")