From 8ff739a288ff7196bcdce459fbdf23d96889c338 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 16 Aug 2023 21:30:07 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat(test=5Fprocess.py):=20add?= =?UTF-8?q?=20tests=20for=20loading=20langchain=20object=20with=20and=20wi?= =?UTF-8?q?thout=20cached=20session?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 fix(test_process.py): import missing functions and modules to fix test failures --- tests/test_process.py | 54 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/tests/test_process.py b/tests/test_process.py index 2d0c349ce..a0d91b5df 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -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