Download scripts/dev/2_test_graph_operation.py from SlappAI/Singularity: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/SlappAI/Singularity/resolve/c8aa03645367f13b28133e72d9204fa09654b00a/scripts/dev/2_test_graph_operation.py
- Command line
-
hf download hf://SlappAI/Singularity@c8aa03645367f13b28133e72d9204fa09654b00a/scripts/dev/2_test_graph_operation.py
-
curl -L -o 2_test_graph_operation.py https://huggingface.co/SlappAI/Singularity/resolve/c8aa03645367f13b28133e72d9204fa09654b00a/scripts/dev/2_test_graph_operation.py
2.56 kB
| # scripts/test_graph_operations.py | |
| import requests | |
| BASE_URL = "http://localhost:5000" | |
| def test_load_graph(): | |
| print("\n--- Testing Graph Loading ---") | |
| response = requests.post(f"{BASE_URL}/load_graph") | |
| print("Load Graph Response:", response.json()) | |
| def test_create_node(): | |
| print("\n--- Testing Node Creation ---") | |
| data = { | |
| "node_id": "patient_123", | |
| "data": { | |
| "name": "John Doe", | |
| "age": 45, | |
| "medical_conditions": ["hypertension", "diabetes"] | |
| }, | |
| "domain": "Healthcare", | |
| "type": "Patient" | |
| } | |
| response = requests.post(f"{BASE_URL}/create_node", json=data) | |
| print("Create Node Response:", response.json()) | |
| def test_query_node(node_id): | |
| print(f"\n--- Testing Node Query ({node_id}) ---") | |
| response = requests.get(f"{BASE_URL}/query_node", params={"node_id": node_id}) | |
| print(f"Query Node {node_id} Response:", response.json()) | |
| def test_list_nodes(): | |
| print("\n--- Testing List All Nodes ---") | |
| response = requests.get(f"{BASE_URL}/list_nodes") | |
| print("List Nodes Response:", response.json()) | |
| def test_list_relationships(): | |
| print("\n--- Testing List All Relationships ---") | |
| response = requests.get(f"{BASE_URL}/list_relationships") | |
| print("List Relationships Response:", response.json()) | |
| def test_traverse_node(node_id, direction): | |
| print(f"\n--- Testing Node Traversal ({node_id}, {direction}) ---") | |
| response = requests.get(f"{BASE_URL}/traverse_node", params={"node_id": node_id, "direction": direction}) | |
| print(f"Traversal Path ({node_id} - {direction}):", response.json()) | |
| def test_inspect_relationships(node_id): | |
| print(f"\n--- Testing Inspect Relationships for Node ({node_id}) ---") | |
| response = requests.get(f"{BASE_URL}/inspect_relationships", params={"node_id": node_id}) | |
| print(f"Inspect Relationships for {node_id}:", response.json()) | |
| if __name__ == "__main__": | |
| # Step 1: Load the Graph | |
| test_load_graph() | |
| # Step 2: Create a sample node | |
| test_create_node() | |
| # Step 3: Query specific nodes | |
| test_query_node("patient_123") | |
| test_query_node("Healthcare") | |
| # Step 4: List all nodes | |
| test_list_nodes() | |
| # Step 5: List all relationships | |
| test_list_relationships() | |
| # Step 6: Traverse nodes (both up and down) | |
| test_traverse_node("patient_123", "up") | |
| test_traverse_node("Healthcare", "down") | |
| # Step 7: Inspect relationships, including hierarchy traversal | |
| test_inspect_relationships("Healthcare") | |
| test_inspect_relationships("patient_123") |