11from typing import Generator
22
3+ import neo4j
34import pytest
45from neo4j import Session
56
1011@pytest .fixture (scope = "class" , autouse = True )
1112def graph_setup (neo4j_session : Session ) -> Generator [None , None , None ]:
1213 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+ "CREATE (a:_CI_A {name:'Alice', height:20, id:42, _id: 1337, caption: 'hello'})-[:KNOWS {year: 2025, id: 41, source: 1, target: 2}]->"
15+ "(b:_CI_A:_CI_B {name:'Bob', height:10, id: 84, size: 11, labels: [1,2]}), (b)-[:RELATED {year: 2015, _type: 'A', caption:'hej'}]->(a)"
1416 )
1517 yield
1618 neo4j_session .run ("MATCH (n:_CI_A|_CI_B) DETACH DELETE n" )
@@ -22,11 +24,30 @@ def test_from_neo4j_graph(neo4j_session: Session) -> None:
2224
2325 VG = from_neo4j (graph )
2426
25- node_ids : list [str ] = [node .element_id for node in graph .nodes ]
27+ sorted_nodes : list [neo4j .graph .Node ] = sorted (graph .nodes , key = lambda x : dict (x .items ())["name" ])
28+ node_ids : list [str ] = [node .element_id for node in sorted_nodes ]
2629
2730 expected_nodes = [
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 ),
31+ Node (
32+ id = node_ids [0 ],
33+ caption = "_CI_A" ,
34+ labels = ["_CI_A" ],
35+ name = "Alice" ,
36+ height = 20 ,
37+ __id = 42 ,
38+ _id = 1337 ,
39+ __caption = "hello" ,
40+ ),
41+ Node (
42+ id = node_ids [1 ],
43+ caption = "_CI_A:_CI_B" ,
44+ labels = ["_CI_A" , "_CI_B" ],
45+ name = "Bob" ,
46+ height = 10 ,
47+ __id = 84 ,
48+ __size = 11 ,
49+ __labels = [1 , 2 ],
50+ ),
3051 ]
3152
3253 assert len (VG .nodes ) == 2
@@ -47,11 +68,31 @@ def test_from_neo4j_result(neo4j_session: Session) -> None:
4768 VG = from_neo4j (result )
4869
4970 graph = result .graph ()
50- node_ids : list [str ] = [node .element_id for node in graph .nodes ]
71+
72+ sorted_nodes : list [neo4j .graph .Node ] = sorted (graph .nodes , key = lambda x : dict (x .items ())["name" ])
73+ node_ids : list [str ] = [node .element_id for node in sorted_nodes ]
5174
5275 expected_nodes = [
53- Node (id = node_ids [0 ], caption = "_CI_A" , labels = ["_CI_A" ], name = "Alice" , height = 20 ),
54- Node (id = node_ids [1 ], caption = "_CI_A:_CI_B" , labels = ["_CI_A" , "_CI_B" ], name = "Bob" , height = 10 ),
76+ Node (
77+ id = node_ids [0 ],
78+ caption = "_CI_A" ,
79+ labels = ["_CI_A" ],
80+ name = "Alice" ,
81+ height = 20 ,
82+ __id = 42 ,
83+ _id = 1337 ,
84+ __caption = "hello" ,
85+ ),
86+ Node (
87+ id = node_ids [1 ],
88+ caption = "_CI_A:_CI_B" ,
89+ labels = ["_CI_A" , "_CI_B" ],
90+ name = "Bob" ,
91+ height = 10 ,
92+ __id = 84 ,
93+ __size = 11 ,
94+ __labels = [1 , 2 ],
95+ ),
5596 ]
5697
5798 assert len (VG .nodes ) == 2
@@ -71,11 +112,32 @@ def test_from_neo4j_graph_full(neo4j_session: Session) -> None:
71112
72113 VG = from_neo4j (graph , node_caption = "name" , relationship_caption = "year" , size_property = "height" )
73114
74- node_ids : list [str ] = [node .element_id for node in graph .nodes ]
115+ sorted_nodes : list [neo4j .graph .Node ] = sorted (graph .nodes , key = lambda x : dict (x .items ())["name" ])
116+ node_ids : list [str ] = [node .element_id for node in sorted_nodes ]
75117
76118 expected_nodes = [
77- Node (id = node_ids [0 ], caption = "Alice" , labels = ["_CI_A" ], name = "Alice" , height = 20 , size = 60.0 ),
78- Node (id = node_ids [1 ], caption = "Bob" , labels = ["_CI_A" , "_CI_B" ], name = "Bob" , height = 10 , size = 3.0 ),
119+ Node (
120+ id = node_ids [0 ],
121+ caption = "Alice" ,
122+ labels = ["_CI_A" ],
123+ name = "Alice" ,
124+ height = 20 ,
125+ size = 60.0 ,
126+ __id = 42 ,
127+ _id = 1337 ,
128+ __caption = "hello" ,
129+ ),
130+ Node (
131+ id = node_ids [1 ],
132+ caption = "Bob" ,
133+ labels = ["_CI_A" , "_CI_B" ],
134+ name = "Bob" ,
135+ height = 10 ,
136+ size = 3.0 ,
137+ __id = 84 ,
138+ __size = 11 ,
139+ __labels = [1 , 2 ],
140+ ),
79141 ]
80142
81143 assert len (VG .nodes ) == 2
0 commit comments