🚀 feat(test_process.py): add tests for loading langchain object with and without cached session
🐛 fix(test_process.py): import missing functions and modules to fix test failures
This commit is contained in:
parent
199ea3b1b8
commit
8ff739a288
1 changed files with 53 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from langflow.processing.process import process_tweaks
|
||||
from langflow.interface.run import build_sorted_vertices_with_caching
|
||||
from langflow.processing.process import load_langchain_object, process_tweaks
|
||||
|
||||
|
||||
def test_no_tweaks():
|
||||
|
|
@ -194,3 +195,54 @@ def test_tweak_not_in_template():
|
|||
tweaks = {"node1": {"param3": 5}}
|
||||
result = process_tweaks(graph_data, tweaks)
|
||||
assert result == graph_data
|
||||
|
||||
|
||||
def test_load_langchain_object_with_cached_session(client, basic_graph_data):
|
||||
# Build the langchain_object once and get the session_id
|
||||
langchain_object1, artifacts1, session_id1 = load_langchain_object(
|
||||
basic_graph_data, None
|
||||
)
|
||||
# Use the same session_id to get the langchain_object again
|
||||
langchain_object2, artifacts2, session_id2 = load_langchain_object(
|
||||
basic_graph_data, session_id1
|
||||
)
|
||||
|
||||
assert session_id1 == session_id2
|
||||
assert id(langchain_object1) == id(langchain_object2)
|
||||
assert artifacts1 == artifacts2
|
||||
|
||||
|
||||
def test_load_langchain_object_with_no_cached_session(client, basic_graph_data):
|
||||
# Provide a non-existent session_id
|
||||
langchain_object1, artifacts1, session_id1 = load_langchain_object(
|
||||
basic_graph_data, "non_existent_session"
|
||||
)
|
||||
# Clear the cache
|
||||
build_sorted_vertices_with_caching.clear_cache()
|
||||
# Use the new session_id to get the langchain_object again
|
||||
langchain_object2, artifacts2, session_id2 = load_langchain_object(
|
||||
basic_graph_data, session_id1
|
||||
)
|
||||
|
||||
assert session_id1 == session_id2
|
||||
assert id(langchain_object1) != id(
|
||||
langchain_object2
|
||||
) # Since the cache was cleared, objects should be different
|
||||
|
||||
|
||||
def test_load_langchain_object_without_session_id(client, basic_graph_data):
|
||||
# Build the langchain_object without providing a session_id
|
||||
langchain_object1, artifacts1, session_id1 = load_langchain_object(
|
||||
basic_graph_data, None
|
||||
)
|
||||
# Build the langchain_object again without providing a session_id
|
||||
langchain_object2, artifacts2, session_id2 = load_langchain_object(
|
||||
basic_graph_data, None
|
||||
)
|
||||
|
||||
assert session_id1 == session_id2
|
||||
|
||||
assert id(langchain_object1) == id(
|
||||
langchain_object2
|
||||
) # Since no session_id was provided, the hash will be based on the graph_data
|
||||
assert artifacts1 == artifacts2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue