1
1
from typing import Generator
2
2
3
+ import neo4j
3
4
import pytest
4
5
from neo4j import Session
5
6
10
11
@pytest .fixture (scope = "class" , autouse = True )
11
12
def graph_setup (neo4j_session : Session ) -> Generator [None , None , None ]:
12
13
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)"
14
16
)
15
17
yield
16
18
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:
22
24
23
25
VG = from_neo4j (graph )
24
26
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 ]
26
29
27
30
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
+ ),
30
51
]
31
52
32
53
assert len (VG .nodes ) == 2
@@ -47,11 +68,31 @@ def test_from_neo4j_result(neo4j_session: Session) -> None:
47
68
VG = from_neo4j (result )
48
69
49
70
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 ]
51
74
52
75
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
+ ),
55
96
]
56
97
57
98
assert len (VG .nodes ) == 2
@@ -71,11 +112,32 @@ def test_from_neo4j_graph_full(neo4j_session: Session) -> None:
71
112
72
113
VG = from_neo4j (graph , node_caption = "name" , relationship_caption = "year" , size_property = "height" )
73
114
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 ]
75
117
76
118
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
+ ),
79
141
]
80
142
81
143
assert len (VG .nodes ) == 2
0 commit comments