From d370c0ae1213d099c02f9a10251f2c3dc5e97e78 Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 16 Apr 2025 14:33:25 +0800 Subject: [PATCH] Fix graph unit test edge direction problem --- tests/test_graph_storage.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/test_graph_storage.py b/tests/test_graph_storage.py index 078bae93..84f975ff 100644 --- a/tests/test_graph_storage.py +++ b/tests/test_graph_storage.py @@ -744,16 +744,25 @@ async def test_graph_batch_operations(storage): print(f"节点 {node3_id} 的出边: {node3_outgoing_edges}") print(f"节点 {node3_id} 的入边: {node3_incoming_edges}") - # 检查是否包含从机器学习来的边,以及到自然语言处理和计算机视觉的边 - has_edge_from_node2 = any(src == node2_id for src, _ in node3_incoming_edges) - has_edge_to_node4 = any(tgt == node4_id for _, tgt in node3_outgoing_edges) - has_edge_to_node5 = any(tgt == node5_id for _, tgt in node3_outgoing_edges) + # 检查是否包含与机器学习、自然语言处理和计算机视觉的连接(忽略方向) + has_connection_with_node2 = any( + (src == node2_id and tgt == node3_id) or (src == node3_id and tgt == node2_id) + for src, tgt in nodes_edges[node3_id] + ) + has_connection_with_node4 = any( + (src == node3_id and tgt == node4_id) or (src == node4_id and tgt == node3_id) + for src, tgt in nodes_edges[node3_id] + ) + has_connection_with_node5 = any( + (src == node3_id and tgt == node5_id) or (src == node5_id and tgt == node3_id) + for src, tgt in nodes_edges[node3_id] + ) assert ( - has_edge_from_node2 - ), f"节点 {node3_id} 的边列表中应包含从 {node2_id} 来的边" - assert has_edge_to_node4, f"节点 {node3_id} 的边列表中应包含到 {node4_id} 的边" - assert has_edge_to_node5, f"节点 {node3_id} 的边列表中应包含到 {node5_id} 的边" + has_connection_with_node2 + ), f"节点 {node3_id} 的边列表中应包含与 {node2_id} 的连接" + assert has_connection_with_node4, f"节点 {node3_id} 的边列表中应包含与 {node4_id} 的连接" + assert has_connection_with_node5, f"节点 {node3_id} 的边列表中应包含与 {node5_id} 的连接" print("无向图特性验证成功:批量获取的节点边包含所有相关的边(无论方向)")