2024-01-17 21:22:19 +00:00
|
|
|
from langchain_community.graphs.neo4j_graph import value_sanitize
|
|
|
|
|
|
|
|
|
2024-02-05 19:22:06 +00:00
|
|
|
def test_value_sanitize_with_small_list(): # type: ignore[no-untyped-def]
|
2024-01-17 21:22:19 +00:00
|
|
|
small_list = list(range(15)) # list size > LIST_LIMIT
|
|
|
|
input_dict = {"key1": "value1", "small_list": small_list}
|
|
|
|
expected_output = {"key1": "value1", "small_list": small_list}
|
|
|
|
assert value_sanitize(input_dict) == expected_output
|
|
|
|
|
|
|
|
|
2024-02-05 19:22:06 +00:00
|
|
|
def test_value_sanitize_with_oversized_list(): # type: ignore[no-untyped-def]
|
2024-01-17 21:22:19 +00:00
|
|
|
oversized_list = list(range(150)) # list size > LIST_LIMIT
|
|
|
|
input_dict = {"key1": "value1", "oversized_list": oversized_list}
|
|
|
|
expected_output = {
|
|
|
|
"key1": "value1"
|
|
|
|
# oversized_list should not be included
|
|
|
|
}
|
|
|
|
assert value_sanitize(input_dict) == expected_output
|
|
|
|
|
|
|
|
|
2024-02-05 19:22:06 +00:00
|
|
|
def test_value_sanitize_with_nested_oversized_list(): # type: ignore[no-untyped-def]
|
2024-01-17 21:22:19 +00:00
|
|
|
oversized_list = list(range(150)) # list size > LIST_LIMIT
|
|
|
|
input_dict = {"key1": "value1", "oversized_list": {"key": oversized_list}}
|
|
|
|
expected_output = {"key1": "value1", "oversized_list": {}}
|
|
|
|
assert value_sanitize(input_dict) == expected_output
|
|
|
|
|
|
|
|
|
2024-02-05 19:22:06 +00:00
|
|
|
def test_value_sanitize_with_dict_in_list(): # type: ignore[no-untyped-def]
|
2024-01-17 21:22:19 +00:00
|
|
|
oversized_list = list(range(150)) # list size > LIST_LIMIT
|
|
|
|
input_dict = {"key1": "value1", "oversized_list": [1, 2, {"key": oversized_list}]}
|
|
|
|
expected_output = {"key1": "value1", "oversized_list": [1, 2, {}]}
|
|
|
|
assert value_sanitize(input_dict) == expected_output
|
2024-03-08 03:21:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_value_sanitize_with_dict_in_nested_list(): # type: ignore[no-untyped-def]
|
|
|
|
input_dict = {
|
|
|
|
"key1": "value1",
|
|
|
|
"deeply_nested_lists": [[[[{"final_nested_key": list(range(200))}]]]],
|
|
|
|
}
|
|
|
|
expected_output = {"key1": "value1", "deeply_nested_lists": [[[[{}]]]]}
|
|
|
|
assert value_sanitize(input_dict) == expected_output
|