From d39dd5fc4a753c6e076bf4e3f0088ac9ba371916 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 16 Aug 2023 22:38:18 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(test=5Fcache.py):=20import?= =?UTF-8?q?=20correct=20compute=5Fdict=5Fhash=20function=20from=20langflow?= =?UTF-8?q?.services.cache.utils=20module=20=F0=9F=90=9B=20fix(test=5Fcach?= =?UTF-8?q?e.py):=20fix=20clear=5Fcache=20function=20call=20by=20passing?= =?UTF-8?q?=20session=5Fid=20parameter=20=F0=9F=90=9B=20fix(test=5Fcache?= =?UTF-8?q?=5Fmanager.py):=20import=20CacheManager=20from=20langflow.servi?= =?UTF-8?q?ces.chat.cache=20module=20instead=20of=20langflow.services.cach?= =?UTF-8?q?e.manager=20=F0=9F=90=9B=20fix(test=5Fcli.py):=20convert=20temp?= =?UTF-8?q?=5Fdir=20to=20string=20before=20checking=20if=20it=20is=20in=20?= =?UTF-8?q?COMPONENTS=5FPATH=20=F0=9F=90=9B=20fix(test=5Fprocess.py):=20fi?= =?UTF-8?q?x=20clear=5Fcache=20function=20call=20by=20passing=20session=5F?= =?UTF-8?q?id=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_cache.py | 22 ++++------------------ tests/test_cache_manager.py | 2 +- tests/test_cli.py | 2 +- tests/test_process.py | 2 +- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index 50698c304..94e4e8553 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,5 +1,6 @@ import json from langflow.graph import Graph +from langflow.services.cache.utils import compute_dict_hash import pytest from langflow.interface.run import ( @@ -41,8 +42,9 @@ def langchain_objects_are_equal(obj1, obj2): # Test build_langchain_object_with_caching -def test_build_langchain_object_with_caching(basic_data_graph): - build_langchain_object_with_caching.clear_cache() +def test_build_langchain_object_with_caching(client, basic_data_graph): + session_id = compute_dict_hash(basic_data_graph) + build_langchain_object_with_caching.clear_cache(session_id) graph = build_langchain_object_with_caching(basic_data_graph) assert graph is not None @@ -53,19 +55,3 @@ def test_build_graph(basic_data_graph): assert graph is not None assert len(graph.nodes) == len(basic_data_graph["nodes"]) assert len(graph.edges) == len(basic_data_graph["edges"]) - - -# Test cache size limit -def test_cache_size_limit(basic_data_graph): - build_langchain_object_with_caching.clear_cache() - for i in range(11): - modified_data_graph = basic_data_graph.copy() - nodes = modified_data_graph["nodes"] - node_id = nodes[0]["id"] - # Now we replace all instances ode node_id with a new id in the json - json_string = json.dumps(modified_data_graph) - modified_json_string = json_string.replace(node_id, f"{node_id}_{i}") - modified_data_graph_new_id = json.loads(modified_json_string) - build_langchain_object_with_caching(modified_data_graph_new_id) - - assert len(build_langchain_object_with_caching.cache) == 10 diff --git a/tests/test_cache_manager.py b/tests/test_cache_manager.py index 660512634..a560aff88 100644 --- a/tests/test_cache_manager.py +++ b/tests/test_cache_manager.py @@ -2,7 +2,7 @@ from io import StringIO import pandas as pd import pytest -from langflow.services.cache.manager import CacheManager +from langflow.services.chat.cache import CacheManager from PIL import Image diff --git a/tests/test_cli.py b/tests/test_cli.py index 408500d7a..c990ef9e8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -27,4 +27,4 @@ def test_components_path(runner, client, default_settings): ) assert result.exit_code == 0, result.stdout settings_manager = utils.get_settings_manager() - assert temp_dir in settings_manager.settings.COMPONENTS_PATH + assert str(temp_dir) in settings_manager.settings.COMPONENTS_PATH diff --git a/tests/test_process.py b/tests/test_process.py index a0d91b5df..29c125abf 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -218,7 +218,7 @@ def test_load_langchain_object_with_no_cached_session(client, basic_graph_data): basic_graph_data, "non_existent_session" ) # Clear the cache - build_sorted_vertices_with_caching.clear_cache() + build_sorted_vertices_with_caching.clear_cache(session_id1) # Use the new session_id to get the langchain_object again langchain_object2, artifacts2, session_id2 = load_langchain_object( basic_graph_data, session_id1