99
1010@pytest .fixture (scope = "class" , autouse = True )
1111def graph_setup (neo4j_session : Session ) -> Generator [None , None , None ]:
12- neo4j_session .run ("CREATE (a:_CI_A {name:'Alice'})-[:KNOWS]->(b:_CI_A:_CI_B {name:'Bob'}), (b)-[:RELATED]->(a)" )
12+ neo4j_session .run (
13+ "CREATE (a:_CI_A {name:'Alice', height:20})-[:KNOWS {year: 2025}]->(b:_CI_A:_CI_B {name:'Bob', height:10}), (b)-[:RELATED {year: 2015}]->(a)"
14+ )
1315 yield
1416 neo4j_session .run ("MATCH (n:_CI_A|_CI_B) DETACH DELETE n" )
1517
@@ -23,8 +25,8 @@ def test_from_neo4j_graph(neo4j_session: Session) -> None:
2325 node_ids : list [str ] = [node .element_id for node in graph .nodes ]
2426
2527 expected_nodes = [
26- Node (id = node_ids [0 ], caption = "_CI_A" , labels = ["_CI_A" ], name = "Alice" ),
27- Node (id = node_ids [1 ], caption = "_CI_A:_CI_B" , labels = ["_CI_A" , "_CI_B" ], name = "Bob" ),
28+ Node (id = node_ids [0 ], caption = "_CI_A" , labels = ["_CI_A" ], name = "Alice" , height = 20 ),
29+ Node (id = node_ids [1 ], caption = "_CI_A:_CI_B" , labels = ["_CI_A" , "_CI_B" ], name = "Bob" , height = 10 ),
2830 ]
2931
3032 assert len (VG .nodes ) == 2
@@ -36,3 +38,27 @@ def test_from_neo4j_graph(neo4j_session: Session) -> None:
3638 (node_ids [0 ], node_ids [1 ], "KNOWS" ),
3739 (node_ids [1 ], node_ids [0 ], "RELATED" ),
3840 ]
41+
42+
43+ @pytest .mark .requires_neo4j_and_gds
44+ def test_from_neo4j_graph_full (neo4j_session : Session ) -> None :
45+ graph = neo4j_session .run ("MATCH (a:_CI_A|_CI_B)-[r]->(b) RETURN a, b, r ORDER BY a" ).graph ()
46+
47+ VG = from_neo4j (graph , node_caption = "name" , relationship_caption = "year" , size_property = "height" )
48+
49+ node_ids : list [str ] = [node .element_id for node in graph .nodes ]
50+
51+ expected_nodes = [
52+ Node (id = node_ids [0 ], caption = "Alice" , labels = ["_CI_A" ], name = "Alice" , height = 20 , size = 60.0 ),
53+ Node (id = node_ids [1 ], caption = "Bob" , labels = ["_CI_A" , "_CI_B" ], name = "Bob" , height = 10 , size = 3.0 ),
54+ ]
55+
56+ assert len (VG .nodes ) == 2
57+ assert sorted (VG .nodes , key = lambda x : x .name ) == expected_nodes # type: ignore[attr-defined]
58+
59+ assert len (VG .relationships ) == 2
60+ vg_rels = sorted ([(e .source , e .target , e .caption ) for e in VG .relationships ], key = lambda x : x [0 ])
61+ assert vg_rels == [
62+ (node_ids [0 ], node_ids [1 ], "2025" ),
63+ (node_ids [1 ], node_ids [0 ], "2015" ),
64+ ]
0 commit comments